CREATE VIEW search_song AS SELECT href('song', r.id, r.title) AS title, r.title AS search_title, ( SELECT br(href('artist', a.id, a.name)) FROM credit c JOIN artist a ON (c.artist_id = a.id) WHERE (c.song_id = r.id AND c.type_id = 0) ) AS artist, ( SELECT comma(a.name) FROM credit c JOIN artist a ON (c.artist_id = a.id) WHERE (c.song_id = r.id AND c.type_id = 0) ) AS search_artist, ( SELECT br(href('artist', a.id, a.name)) FROM credit c JOIN artist a ON (c.artist_id = a.id) WHERE (c.song_id = r.id AND c.type_id = 1) ) AS music, ( SELECT comma(a.name) FROM credit c JOIN artist a ON (c.artist_id = a.id) WHERE (c.song_id = r.id AND c.type_id = 1) ) AS search_music, ( SELECT br(href('artist', a.id, a.name)) FROM credit c JOIN artist a ON (c.artist_id = a.id) WHERE (c.song_id = r.id AND c.type_id = 2) ) AS lyrics, ( SELECT comma(a.name) FROM credit c JOIN artist a ON (c.artist_id = a.id) WHERE (c.song_id = r.id AND c.type_id = 2) ) AS search_lyrics, r.year AS year, r.year AS search_year, --href('album', alb.id, alb.title) AS album, --alb.title AS search_album, r.id AS id FROM song r --LEFT JOIN album alb ON (r.album_id = alb.id) -- Uncomment next line for 'presorted' -- ORDER BY search_title ;