tbl_goal_context (many-to-many table)
rowId(PK) | goalRowId(FK) | contextRowId (FK) |
1 | 2 | 5 |
tbl_context_items
rowId(PK) | ... |
5 | ... |
tbl_context_categories_items (many-to-many table)
rowId(PK) | catRowId(FK) | itemRowId(FK) |
1 | 3 | 5 |
我试图列出tbl\u context\u项中的行,这些行通过两个多对多表连接,其中catRowId和goalRowId是已知的。
例如,假设我想从tbl\u context\u项中提取连接到的所有行
goalRowId = 2
和
catRowId = 3
“错误:不明确的列名:tbl\u goal\u context.goalRowId无法执行语句”
SELECT tbl_context_categories_items.itemRowId, tbl_context_categories_items.catRowId, tbl_goal_context.goalRowId, tbl_goal_context.contextRowId, tbl_context_items.rowId AS rowId, tbl_context_items.shortText AS shortText, tbl_context_items.userMade AS userMade
FROM tbl_context_categories_items
INNER JOIN tbl_goal_context ON tbl_goal_context.contextRowId = tbl_context_items.rowId
INNER JOIN tbl_goal_context ON tbl_context_categories_items.itemRowId = tbl_context_items.rowId
WHERE tbl_context_categories_items.catRowId = 3
AND tbl_goal_context.goalRowId = 2
ORDER BY tbl_context_items.shortText ASC