
CREATE TEMP TABLE CoreCache (
       OrderID INTEGER PRIMARY KEY,
       ModelID INTEGER,
       ItemID TEXT);
INSERT INTO CoreCache (ModelID, ItemID) 
       SELECT 39, CoreTracks.TrackID 
       	      FROM CoreTracks CROSS JOIN CoreArtists,CoreAlbums WHERE CoreArtists.ArtistID = CoreTracks.ArtistID AND CoreAlbums.AlbumID = CoreTracks.AlbumID  AND CoreTracks.PrimarySourceID = 1  
	      ORDER BY
			CoreAlbums.ArtistNameSortKey ASC,
			CoreAlbums.TitleSortKey ASC,
			CoreTracks.Disc ASC,
			CoreTracks.TrackNumber ASC;
INSERT INTO CoreCache (ModelID, ItemID)
       SELECT 1, CoreArtists.ArtistID
       	    FROM CoreArtists WHERE CoreArtists.ArtistID IN
	    (SELECT CoreTracks.ArtistID FROM CoreTracks, CoreCache
	    	    WHERE CoreCache.ModelID = 39 AND
		    CoreCache.ItemID = CoreTracks.TrackID )
            ORDER BY NameSortKey;
