Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can this be done? Coalesce join

Status
Not open for further replies.

Chumley40

Programmer
Jan 24, 2005
71
US
I want to retrieve the first data available based on an or statement, but don't know how.
INNER JOIN table t
ON t.GUID = child.GUID
or t.GUID = 0)

so if t.guid = child.guid returns something I want only it. If not I want the data where t.guid = 0

Does this make sense? Can it be done?
 
I think something like this will do the trick for you:

Code:
ON t.GUID = child.GUID
        or (t.GUID = 0 and t.GUID <> child.GUID)

Let me know if you have any questions.

Hope this helps,

Alex

[small]----signature below----[/small]
With all due respect, Don Bot, I don't think we should rely on an accident happening. Let's kill him ourselves.

Ignorance of certain subjects is a great part of wisdom
 
Try this

Code:
select d.GUID,isnull(chd,0) 
from
     (select a.GUID,b.GUID as chd 
       from table_1 a
         Left join table_2 b
           on a.GUID=b.GUID)d

Well Done is better than well said
- Ben Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top