Subject Re: [firebird-support] nested join sql help
Author Svein Erling Tysvær
>select n.UserID, p.ProdName, pv.ProdVer, b.id, b.text from Bugs b join
>(productversions pv join products p on pv.ProductID=p.id) on
>b.ProductVersionID=pv.id left join Notifications n on b.id=N.BugID where
>n.name='myuser'

Hmm, the problem is not so much to understand the SQL as to try to understand what you actually want... Though there is one questionable bit in your query, and that is the where clause. I have read (no practical experience myself) that the only way to limit rows from the right side of a left join is in the join clause - doing it in the where clause is basically saying "Give me every row of B whether or not you find a match in table A, but only if those records match this value in table A", i.e. you are confusing Firebird and ought to receive a syntax error (my personal opinion). Hence, the first thing to clean up will be:

select n.UserID, p.ProdName, pv.ProdVer, b.id, b.text from Bugs b join
(productversions pv join products p on pv.ProductID=p.id) on
b.ProductVersionID=pv.id left join Notifications n on b.id=N.BugID and n.name='myuser'
where...

For readability, I would consider changing all this to

select n.UserID, p.ProdName, pv.ProdVer, b.id, b.text
from Bugs b
join productversions pv on b.ProductVersionID=pv.id
join products p on pv.ProductID=p.id
left join Notifications n on b.id=N.BugID and n.name='myuser'
where...

but I guess this does not make any practical difference. Anyway, if this is not what you want, then please describe your problem a bit more.

HTH,
Set