我有一张桌子:
brand(id, parent_id, name)
1 0 Apple
2 1 Macbook Air
3 1 Iphone 4S
imgae(id, brand_id, image)
1 2 mac.png
2 3 iphone.png
和mysql:
SELECT br.name, img.image FROM image as img
LEFT JOIN brand AS br ON br.parent_id = img.brand_id
结果是:
Macbook Air | mac.png
Iphone 4S | iphone.png
如何从表品牌中获取父名称
Macbook Air | mac.png | Apple
Iphone 4S | iphone.png | Apple