I have written a query which joins 3 tables where i need to inner join 2 tables and then inner join the whole result set with another join.
The query is as follows:
SELECT R.ID,
R.Title,
R.Requirement_Text,
R.Req_Owner,
D.desname,
D.team,
D.stage,
D.comm
FROM Req R
LEFT JOIN
(
SELECT d1.ID AS 'id',
d1.designername AS 'desname',
d1.teamname AS 'team',
s.stage AS 'stage',
s.comments As 'comm'
FROM descomments d1
LEFT JOIN stagecomments s ON d1.ID = s.ID
AND d1.designername = s.designername
) D ON R.ID = D.id
WHERE R.ProjectID = 'STE 11.2'
ORDER BY R.Priority
But i am getting following error:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 'SELECT d1.ID AS 'id',d1.designername AS 'desname',d1.teamname A
You don’t need the ‘descomments’ after the first left join.. you’re actually joining to D, which is the result of your sub-join..