1

是否可以在没有任何子查询的情况下执行此查询?或者更少的代码?得到同样的结果。

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

3 回答 3

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'
于 2013-03-27T14:12:08.777 回答
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

要进一步了解有关联接的更多信息,请访问以下链接:

于 2013-03-27T14:11:24.393 回答
0

只需将您的tblcandtblb作为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;
于 2013-03-27T14:14:26.840 回答