以下是我的表格:
表1:
ID | data1 | data2
1 | xxx | xxx
2 | xxx | xxx
表2:
ID | table1_id
20 | 1
21 | 1
25 | 2
26 | 2
表3:
ID | table2_id
30 | 20
31 | 21
32 | 25
33 | 26 <--
我已用箭头标记相关行(表3:ID = 33 | table2_id = 26 )
现在,我希望匹配ID与表1中的数据1和数据2.在这种情况下: 2
我试了一下......
SELECT t1."ID"
FROM table AS t1
INNER JOIN table2 AS tb2
ON t1."ID" = t2."ID"
INNER JOIN table3 AS t3
ON t2."ID" = 26
......但它什么都没有。有人给我一个工作子查询:)
答案 0 :(得分:1)
你加入了错误的领域
SELECT t1."ID"
FROM table AS t1
INNER JOIN table2 AS t2
ON t1."ID" = t2.table1_id
INNER JOIN table3 AS t3
ON t2."ID" = t3.table2_id
WHERE t3."ID" = 33