ワンBuyu:
私は親IDが定義されているすべての孫を取得したい、関連する3つのテーブルを持っています。私は、MySQLとPHPを使用しています。
--------- RELATIOSHIP -------
Parent has many child
Child has many grandchild
-------Parent table------
| parentId | otherAttr |
-------------------------
------------ Child table ---------------
| childId | parentId | otherAttr |
----------------------------------------
------------ grandChild table ----------
| grandId | childId | otherAttr |
----------------------------------------
Mureinik:
参加するのカップルは、トリックを行う必要があります。
SELECT g.*
FROM grandchild g
JOIN child c ON g.childId = c.childId
JOIN parent p ON c.parentId = p.parentId
WHERE p.parentId = <somevalue>