[英]writing a Select query to deduct one table from another
I am just a little confuse to how write the below query : 我只是有点混淆如何写下面的查询:
I have two tables 我有两张桌子
tbl_one
ID TEXT
1 test1
2 test2
3 test3
4 test4
5 test5
and 和
tbl_two
ID userID tblone_ID
1 50 1
2 100 1
3 100 2
I am looking to get rows of tbl_one which are not appear in tbl_two but for the certain user . 我希望获得tbl_one的行,这些行不会出现在tbl_two中,而是针对特定用户。
for example by below select : 例如,通过以下选择:
select * from tbl_one, tbl_two
where (tbl_two.tblone_ID !=tbl_one.ID and tbl_two.userID==50)
my desire resault will be 我的愿望将是
Desire resalt:
ID TEXT
2 test2
3 test3
4 test4
5 test5
SELECT a.*
FROM tableA a
LEFT JOIN tableB b
on a.ID = b.tblone_ID AND
b.userID = 50
WHERE b.tblone_ID IS NULL
select *
from tbl_one
where ID not in (select tblone_ID
from tbl_two
where userID = 50)
select * from tbl_one where tbl_one.ID not in ( Select tblone_ID FRom tbl_two where userID=50) SELECT * from tbl_one inner Join tbl_two on tbl_one.ID !=tblone_ID where userID=50
SELECT * FROM tbl_one
LEFT JOIN tbl_two on tbl_one.ID = tbl_two.tblone_ID
WHERE tbl_one.ID IS NULL AND tbl_two.userID = 50
you may try this 你可以试试这个
select * from tbl_one t1
where t1.id not in (select tblone_id from tbl_two where tbl_two.userid=50)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.