SELECT
 * 
FROM 
( 
SELECT 
 ( @bib := <<biblionumber>>) as biblionumber,
 ( @Nyear := <<number of year to search>>) as title,
 0 as subtitle,
 0 as author,
 0 as score
) AS set_variables 
WHERE 0 = 1 
UNION 
select suggestions.biblionumber,
ExtractValue(marcxml,'//datafield[@tag="200"]/subfield[@code="a"]') title,
ifnull(ExtractValue(marcxml,'//datafield[@tag="200"]/subfield[@code="e"]'),"") subtitle,
ifnull(ExtractValue(marcxml,'//datafield[@tag="200"]/subfield[@code="f"]'),"") author,
score from biblioitems
join (
	select items.biblionumber, count(distinct old_issues.borrowernumber) score from old_issues,items
	where
	items.itemnumber=old_issues.itemnumber and
	old_issues.issuedate > DATE_SUB(NOW(),INTERVAL @Nyear YEAR) and
	borrowernumber in (
		select distinct borrowernumber from items,old_issues where items.itemnumber=old_issues.itemnumber and items.biblionumber=@bib and borrowernumber is not null
	)
    and items.biblionumber <> @bib
    group by items.biblionumber
    order by score desc,rand()
    limit 10
    ) suggestions
on biblioitems.biblionumber=suggestions.biblionumber;
