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
 General SQL Server Forums
 New to SQL Server Programming
 Join Statement

Author  Topic 

Deon Smit
Starting Member

47 Posts

Posted - 2008-11-18 : 04:45:07
Hi all.

My 2 tables are as follow.

Table ITEM
Item | Supp |
-------------
1 | 22
2 |
3 | 11

Table SUPPLIER
Supp | Name
--------------
11 | ABC
22 | DEF
33 | ZYX

My Script.

Select A.item b.name from ITEM A
join SUPPLIER B
on A.SUPP = B.SUPP

My results.

Item | NAME |
-------------
1 | DEF
3 | ABC

I want it not to loose my second item. It can even display it then as..


Item | NAME |
-------------
1 | DEF
2 |
3 | ABC

or


Item | NAME |
-------------
1 | DEF
2 | NONE
3 | ABC

Please Help.




sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-11-18 : 04:50:30
Select A.item ,ISNULL(b.name,'NONE') from ITEM A
left join SUPPLIER B
on A.SUPP = B.SUPP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-18 : 04:53:36
or use Coalesce instead of isnull


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-18 : 06:20:38
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx
Go to Top of Page

Deon Smit
Starting Member

47 Posts

Posted - 2008-11-18 : 09:52:09
Thanks all. I manage to use a left outer join. Worked like a dream.
Go to Top of Page
   

- Advertisement -