Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two table one is item table which contains the itemid,itemname,itemprice and another for userpermission which contains productid,userid . I want to listed down the items which are in the item table but not in the userpermission table for a particular user. Means for userid 1 i want to list the items which are in item table but not in userpermission .

where Userid is stored in session
Posted
Comments
kiran dangar 20-Oct-11 1:26am    
Hi, your question is confusing.. please elaborate.
where is the relation between UserID & your Item Table ???
kumar_k508 20-Oct-11 1:38am    
Give more detail explanation about your query with relation between two tables..

SQL
Select * from table1 Inner join table 2 on 
table1.FirstID = table2.FirstID
That is the syntax regarding on how to use Inner Join must have a primary key or a foreign key
Basically im proposing something to you.,,
If your using SQL server it is better to put in your SQL statement and try to execute it in new query of your database. In that way you can easily see what is the error of your SQL command.

Happy coding
 
Share this answer
 
v2
SQL
Select * from Item where ItemID not in (select ItemID from UserPermission where UserID=ID)
 
Share this answer
 
v2
Try this
SQL
declare @Id int
set @Id= 1
select * from Item I left outer join UserPermission U on I.ItemId = U.ItemId
where ItemId is null and userId = @Id
 
Share this answer
 
you are mixing product_id and item_id. what i have understood is as follows
you have an item table and userPermission table. userPermissiontable contains the user_id and item_id. now you want to display those items which are in user's permission. if right, here is query

SQL
Declare @userID INT
set @userID = 1

Select * from UserPermission up
where 
up.userid = @userID
up.item_id IN (Select i.item_id from item i)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900