[英]How to select the records from a table which is not in the result of select Query(select query might be joins of 2 or more tables)
考慮:
table t1(a,b,c)
table t2(a,d,e)
table t3(r,f,g)
select t1.a,t1.b,t1.c,t2.d,t2.e
from t1 join t2
on (t1.a=t2.a)
並且還需要根據t1.a和t3.r從t3表中選擇不在上述查詢結果中的記錄
如果在t1.a
和t3.r
之間存在關系,則只需在表之間進行t1.a
select t1.a,
t1.b,
t1.c,
t2.d,
t2.e,
t3.g
from t1
join t2 on t1.a = t2.a
join t3 on t1.a = t3.r;
如果t1.a
和t3.r
之間沒有關系,則:
SELECT t1,*, t2.*, t3.*
FROM t1
JOIN t2 ON t1.a = t2.a
JOIN t3 ON 1=1
嘗試在WHERE
子句中使用NOT IN
, WHERE
如下:
SELECT
t3.*
FROM
t3 AS t3
WHERE
t3.r NOT IN
(select t1.a
from t1 join t2
on (t1.a=t2.a))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.