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
 SQL / Not existing records as blank cells

Author  Topic 

Mikk2007
Starting Member

1 Post

Posted - 2007-10-07 : 17:55:44
hi

I have data in two tables.

NAMES
ID Name
1 FIRST
2 SECOND


CODES
ID CodeType Code
1 A xyz
1 B abc
1 C gfd
2 A xdz
2 B dca



I want to join the two tables to add the Code of CodeType "C" to the records of NAMES

Result Example
ID Name Code
1 FIRST gfd
2 SECOND ----


I want to have all records from the names with the codetype C, if there is no record with the codetype c for a given ID, the cell should be blank to identify for which ID's the CodeType C is mising.

how should the sql statement look like?

Please help!
thanks in advance!

Mikk

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-10-07 : 22:32:38
select n.id, n.name, c.code
from names n
left join codes c on n.id=c.id and c.codetype='C'


elsasoft.org
Go to Top of Page
   

- Advertisement -