是否可以在没有任何子查询的情况下执行此查询?或者更少的代码?得到同样的结果。
SELECT person
FROM tbla
WHERE person IN
(SELECT person
FROM tblb
WHERE age IN
(SELECT age
FROM tblc
where age = '20'));
是否可以在没有任何子查询的情况下执行此查询?或者更少的代码?得到同样的结果。
SELECT person
FROM tbla
WHERE person IN
(SELECT person
FROM tblb
WHERE age IN
(SELECT age
FROM tblc
where age = '20'));
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'
您可以使用连接,但需要一个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
要进一步了解有关联接的更多信息,请访问以下链接:
只需将您的tblc
andtblb
作为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;