Working query
( SELECT R.ref as ref, R.field8, R.file_extension, DATE_FORMAT(R.creation_date,'%e/%c/%Y') as date, Ra.rank as rank FROM resource R INNER JOIN resource_ranking Ra ON R.ref = Ra.ref_id ORDER BY Ra.rank limit 2 ) UNION ALL ( SELECT R.ref as ref, R.field8, R.file_extension, DATE_FORMAT(R.creation_date,'%e/%c/%Y') as date, '99' as rank FROM resource R LEFT JOIN ( SELECT ref_id FROM resource_ranking ORDER BY rank LIMIT 2 ) AS B ON R.ref = B.ref_id INNER JOIN collection_resource C ON R.ref = C.resource WHERE B.ref_id IS NULL AND R.ref != '-1' AND C.collection = 1 ) ORDER BY rank ASC, ref DESC LIMIT 0, 8
the above query is working fine i wants to add another table to existing query using inner joins
Below is my written query using inner joins
( SELECT R.ref as ref, R.field8, R.file_extension, DATE_FORMAT(R.creation_date,'%e/%c/%Y') as date, Ra.rank as rank FROM resource R INNER JOIN resource_ranking Ra ON R.ref = Ra.ref_id ORDER BY Ra.rank limit 2 INNER JOIN resource_rating Rr ON R.ref = Rr.resource_id ORDER BY Rr.rating DESC ) UNION ALL ( SELECT R.ref as ref, R.field8, R.file_extension, DATE_FORMAT(R.creation_date,'%e/%c/%Y') as date, '99' as rank FROM resource R LEFT JOIN ( SELECT ref_id FROM resource_ranking ORDER BY rank LIMIT 2 ) AS B ON R.ref = B.ref_id INNER JOIN collection_resource C ON R.ref = C.resource WHERE B.ref_id IS NULL AND Rr.userid=1 AND R.ref != '-1' AND C.collection = 1 ) ORDER BY rank ASC, ref DESC LIMIT 0, 8
However, this gives the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN resource_rating Rr ON R.ref = Rr.resource_id ORDER BY Rr.rating DESC' at line 3