因此,假设我有一个包含以下各列的表(用户):
名字|姓|年龄|价值|费用
是否有一种方法可以重构此查询,以使我的所有行的所有列都都存在于“ where exist”子查询中的姓氏和姓氏?
Select * from users u
where exists (
select firstname, surname from users u2
where age = 20
)
假设select * from users where age = 20
由于某种原因无法正常工作,我想您正在寻找类似这样的内容:
select
*
from
users u
where exists
(select * from users where age = 20 and u.first_name = first_name and u.last_name = last_name)
您最好加入关键列,如果它们存在的话。您可以在子查询中为表加上别名,并限定那里的列,但不必这样做。