join 2 tables on differnt joins based on 2 different conditions

Posted on 2011-09-19
Last Modified: 2012-05-12
when you join 2 tables on differnt joins based on 2 different values, is it possible to consolidate the 2 queries into 1?

select * from a join b on = b.id1 and b.indicator = 0
select * from a join b on = b.id2 and b.indicator = 1
Question by:25112

Accepted Solution

twol earned 425 total points
ID: 36561080
select * from a inner join b
on ( = b.id1 and b.indicator = 0) or ( = b.id2 and b.indicator = 1 )
LVL 18

Assisted Solution

deighton earned 75 total points
ID: 36561644
I believe the SQL you gave does exactly what you ask, so the answer is yes

Author Comment

ID: 36562190

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mysql joining from the same table 6 37
SSRS troubles 4 21
sql server group by every 2hrs 5 21
Common Records between Sub Queries 4 14
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now