我有问题...... 在table1中我有一个id,我必须比较table2中的id,然后获取table2中的第二个id并将其与table3进行比较并得到一个数据。 实施例
TABLE1
ID NAME ECC...
1 Jhon
2 Frank
TABLE2
ID ID2 ECC..
1 4
2 8
TABLE3
ID NAME
4 Sea
8 Hello
如果我查找id 1,结果必须是Sea 如果我查找id 2,结果必须是Hello
谢谢!
答案 0 :(得分:1)
SELECT Table3.NAME
FROM Table1
INNER JOIN Table2
ON Table1.ID = Table2.ID
INNER JOIN Table3
ON Table3.ID = Table2.ID2
WHERE Table1.ID = 1 -- Your Search here
答案 1 :(得分:0)
您应该使用加入。
您的查询将如下所示:
SELECT t3.name
FROM table3 t3
LEFT JOIN table2 t2 ON t3.id = t2.id2
LEFT JOIN table1 t1 ON t2.id2 = t1.id
WHERE t1.id = <your_number>
答案 2 :(得分:-1)
查询:
SELECT a.name As Name FROM table3 a JOIN
(SELECT b.id2 AS id FROM table1 a JOIN table2 b ON a.id = b.id)b
ON a.id = b.id where b.id = <your id number (1,2) Anything>
答案 3 :(得分:-1)
select Table2.Id,Table3.Name from Table1 inner join Table2 on Table2.ID2 = Table3.Id
答案 4 :(得分:-2)
应该是这样的:
select table3.name as name3
from table3
where table3.ID = table2.ID2
and table2.ID = table1.ID
and table1.ID = <YOURNUMBERHERE>