2013-03-27 121 views
1

是否可以在沒有任何子查詢的情況下執行此查詢?或者更少的代碼?獲得相同的結果。查詢沒有子查詢? SQL

SELECT person 
FROM tbla 
WHERE person IN 
(SELECT person 
FROM tblb 
WHERE age IN 
(SELECT age 
FROM tblc 
where age = '20')); 
+1

如果不知道所選表格的結構,則無法真正回答這個問題。 – DanSingerman 2013-03-27 14:11:05

+0

謝謝大家的快速回復。像魅力一樣工作。謝謝! – kvambaam 2013-03-27 14:24:52

回答

1
SELECT tbla.person 
FROM tbla 
inner join tblb on tblb.person = tbla.person 
inner join tblc on tblc.age = tblb.age 
WHERE tblc.age = '20' 
0

可以使用加入,但一個DISTINCT關鍵字是必需的,以消除重複行。

SELECT DISTINCT a.* 
FROM tbla a 
     INNER JOIN tblb b 
      ON a.person = b.person 
     INNER JOIN tblc c 
      ON b.age = c.age 
WHERE c.age = 20 

爲了進一步獲得更多的知識有關加入,請訪問以下鏈接:

0

只要把你的tblctblb作爲INNER JOIN

SELECT tbla.person 
FROM tbla 
INNER JOIN tblb 
    ON tblb.person = tbla.person 
INNER JOIN tblc 
    ON tblc.age = tblb.age 
WHERE tblc.age = 20;