Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

join 2 tables on differnt joins based on 2 different conditions

Posted on 2011-09-19
3
Medium Priority
?
363 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
3 Comments
 
LVL 7

Accepted Solution

by:
twol earned 1700 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 300 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

782 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