On 6/20/2016 3:32 PM, R Smith wrote:
SELECT a.id, MAX(b.orderno) as maxorderno
FROM a
INNER JOIN c on c.a_id = a.id
INNER JOIN b ON b.c_id = c.id
GROUP BY a.id;
-- | maxorder- --- This is what I think you might
actually want,
-- id | no --- it precludes NULLs and is sure to
pick the
-- ------------ | --------- --- correct max when joined to b too.
-- 1 | ORD005
-- 2 | ORD009
And if you do need NULLs, then just change it to "LEFT JOIN b".
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users