Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Left Join misunderstanding

Author  Topic 

Rawler
Starting Member

9 Posts

Posted - 2009-11-11 : 13:00:34
hi guys, well I have a doubt about this join;

I have 2 tables
t1-ITEMS
t1.ItemId
t1.ItemName

t2-ITEMSxUSERS
t2.UserId
t2.ItemId

and I try to bring ALL items of t1, when the item is in t2 show the name and when is not show a null.

I tried this and I got only the items that are in t2, any idea how to solve this?

SELECT *
FROM t1 LEFT JOIN t2 ON t1.ItemId = t2.ItemId
WHERE t2.UserId= 200


Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-11-11 : 13:04:32
Change the WHERE to an AND
SELECT *
FROM t1 LEFT JOIN t2 ON t1.ItemId = t2.ItemId
WHERE AND t2.UserId= 200
Go to Top of Page

Rawler
Starting Member

9 Posts

Posted - 2009-11-11 : 14:18:45
ermmm it worked... wow I feel sad, such a easy solution haha I think I have to change nick or something haha thanks Lamprey you fixed my life.

pd: I dont know if I have to close or submit as resolved or what to do after you solved my question, but thanks again.
Go to Top of Page
   

- Advertisement -