Solved

join 2 tables on differnt joins based on 2 different conditions

Posted on 2011-09-19
3
354 Views
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 a.id = b.id1 and b.indicator = 0
union
select * from a join b on a.id = b.id2 and b.indicator = 1
0
Comment
Question by:25112
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

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

Assisted Solution

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

Author Comment

by:25112
ID: 36562190
works..
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

756 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