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)
 SELECT/WHERE, 2 tables, null value allowed

Author  Topic 

kode82
Starting Member

2 Posts

Posted - 2009-09-09 : 08:33:47
Hi, everyone!

I would appreciate some help/guidance because at the moment I am not sure for what to search the internet.

So for example I have two tables

tBooks

bookid/booktitle/countryid
1/book1/12
2/book2/NULL
3/book3/23

tCountry

countryid/country
12/Country1
23/Country2

In SELECT result I would like to get all the records in tBook table, so that in countryid column I would get either the name of the appropriate country or NULL (or empty string, or something else) value if there was null in the first place.

If I will write WHERE statement then the second row will be left out because of the NULL value.

So the question is what query structure will be the best to use in this situation.

Thanks for reading.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-09-09 : 08:36:11
Try left join!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

kode82
Starting Member

2 Posts

Posted - 2009-09-09 : 09:06:40
Thanks Senthil.

It worked fine.
Go to Top of Page
   

- Advertisement -