SELECT v.id , v.title, v.artist, v.music, v.lyrics, v.year 
FROM
(	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,

	r.id AS id

	FROM song r
	ORDER BY search_title
) AS v
ORDER BY v.search_title 
LIMIT 20 OFFSET 0 ;
