views:

30

answers:

2

iam having 2 tables

table Items Table (this table holds all items iam having)

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. Now i want to write a query on table1 (Items table) so that it displays all items which user1 has NOT chosen.

+2  A: 
select itemid from Items where itemid not in 
(select itemid from users_item where userid = 1)
kekekela
A: 
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;
ceteras