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
 Basic Left join help

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2015-02-12 : 08:52:18
I am not sure here on the syntax. I want to join file a and file b
where a.ent = b.ent and a.suf - b.suf i want one col from file b
which is grc# even if blank.

Select * from mylib.filea a left join
hislib.fileb b
where a.ent = b.ent
and a.suf = b.suf

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-12 : 09:28:14
[code]
Select * from mylib.filea a
left join hislib.fileb b
on a.ent = b.ent
and a.suf = b.suf
[/code]

use ON instead of WHERE. ON is the matching predicate. For LEFT JOINs, it will match on either equal values or nulls, if there are no matching rows from the right side of the join. WHERE is a filtering predicate so would filter out rows where a.ent <> b.ent. If either one is null, the predicate returns false.
Go to Top of Page
   

- Advertisement -