删除表行的典型查询通常是这样的,对吗?
$query1 = odbc_exec($conn, "DELETE FROM table1 WHERE uname1 <> uname2");
但是,如果我想以uname2
位于不同的表中的方式,那该怎么办?
答案 0 :(得分:3)
DELETE FROM table1
WHERE uname1 NOT IN (
SELECT uname2
FROM table2
)
答案 1 :(得分:0)
如果uname1
是唯一的,您可以执行以下操作:
DELETE FROM table1 AS t1
WHERE uname1 NOT IN (
SELECT uname2
FROM table2 AS t2
WHERE t2.uname1 = t1.uname1
);