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 query

Author  Topic 

shoham
Starting Member

6 Posts

Posted - 2011-11-23 : 08:59:30
hello all,

i have a qury somthig like this:
select a.*,b.field1
from tbl_a as a
join tbl_b as b
on a.id=b.id

now tbl_a contains 10 records, but only 7 of them exist in tbl_b,
so when i join them together i get only 7 records.

how can i make the query to get the whole 10 records with null value in "field1"

thanks

Shoham

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-23 : 09:30:18
change the join to LEFT JOIN

select a.*,b.field1
from tbl_a as a
LEFT join tbl_b as b
on a.id=b.id



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

shoham
Starting Member

6 Posts

Posted - 2011-11-23 : 09:36:49
thanks !
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-23 : 09:37:20
welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -