Table parent
parentId | name
Table children
childId | parentId | pictureId | age
Table childrenPictures
pictureId | imgUrl
no i would like to return all parent names with their eldest son's picture (only return parents that have children, and only consider children that have pictures)
so i thought of something like :
Expand|Select|Wrap|Line Numbers
- SELECT p.name AS parentName,
- cp.imgUrl AS imgUrl
- FROM parent AS p
- RIGHT JOIN children AS c ON (p.parentId = c.parentId)
- RIGHT JOIN childrenPictures AS cp ON (c.pictureId = cp.pictureId))
- WHERE c.age IN (SELECT c.age AS age FROM children AS c GROUP BY c.parentId ORDER BY c.age DEST LIMIT 0,1)
Well if anyone has a hint i'd appreciate very much
Thank you very much,
guillermobytes