SELECT a.`title`, a.url, a.img, b.sitesid, a.img, a.mpg, a.mpg, a.avi, a.wmv, a.flv, b.uri, b.idimg, match(a.title, a.stripped, a.url) against ('test') as SCORE, stat FROM sites AS a RIGHT join img AS b on a.sitesid = b.sitesid WHERE match(a.title, a.stripped, a.url) against('test') AND (width / height BETWEEN 0.6 AND 1.4) AND (width > 400 OR height > 400) AND EXISTS (SELECT * FROM sites AS q WHERE stat = 'A' AND img > 14) GROUP BY b.sitesid ORDER BY SCORE DESC LIMIT 100