是否可以在没有任何子查询的情况下执行此查询?或者更少的代码?得到相同的结果。
SELECT person
FROM tbla
WHERE person IN
(SELECT person
FROM tblb
WHERE age IN
(SELECT age
FROM tblc
where age = '20'));
答案 0 :(得分: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'
答案 1 :(得分: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
要进一步了解联接,请访问以下链接:
答案 2 :(得分:0)
只需将tblc
和tblb
作为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;