父亲表
id name age married
9 Max 45 1
儿童桌
id father_id name
12 9 Rose
书桌
id owner_id title nPages
1 12 Harry potter 755
2 12 JDK 124
我试过了
Select father.*, child.*, books.*
FROM fathers father
LEFT JOIN children child
ON child.father_id = father.id
LEFT JOIN books book
ON book.owner_id = child.id
WHERE father.married = 1
LIMIT 1
其中返回父亲和孩子+只有一本书。但我需要按 nPages 排序的孩子拥有的所有书籍。
像这样的东西:
[
name : MAX ,
age : 45,
married : 1,
child => [
father_id => 9,
name => Rose,
books => [
book1 => ...,
book2 => ...
]
]
]
请你帮助我好吗?
笔记!一个父亲只能生一个孩子。