【发布时间】:2023-03-10 18:31:01
【问题描述】:
select *
from table1 t1,
table2 t2,
table3 t3
where t2.parent_id = t1.row_id
and t2.xyz is not null
and (
select count(*)
from table3
where xyz = t2.row_id
) = 0;
它会起作用吗? 我在子查询中使用别名 t2。
我的要求是检查是否在 where 子句中指定条件,以便 table3 中不存在记录,其中 table3 的列 xyz 存储为 table2 的 row_id。
【问题讨论】:
-
您使用的是什么版本的 SQL,您自己尝试过吗?我可能会使用
WHERE NOT EXISTS而不是 count 子查询。请注意,您当前正在table2和table3之间进行交叉连接,这可能不是您想要的。 -
这可能在 Stack Exchange 子站点代码审查中
-
今日提示:切换到现代、明确的
JOIN语法! (如下面@GurV 的回答。)