简体   繁体   English

写一个SQL查询?

[英]writing an sql query?

I'm having 2 tables 我有2张桌子

table Items Table (this table holds all items I'm having) table项目表(此表包含我拥有的所有项目)

itemId
---------
Item1
Item2
Item3
Item4
Item5

table 2 users_item relation 
UserId  || ItemId
1  || Item1
1  || Item2

userId one has stored 2 items Item1,Item2. userId一个已存储2个项目Item1,Item2。 Now I want to write a query on table1 (Items table) so that it displays all items which user1 has NOT chosen. 现在,我想在table1(项目表)上写一个查询,以便显示user1尚未选择的所有项目。

select itemid from Items where itemid not in 
(select itemid from users_item where userid = 1)
select itemid 
from Items i
left join (select ItemId from users_item where userId = 1)chosen on chosen.ItemId = i.itemId
where chosen.ItemId is null;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM