Thursday, 19 September 2013

Using OR Condition in JOINS

Using OR Condition in JOINS

I'm fetching records by doing some multiple Joins. I need to add one more
with OR condition.
There is a table Payment. From Payment have to join with a table
Package1(if Payment.PaymentTypeID=1) OR with a table Package2(if
Payment.PaymentTypeID=3).
Both the tables Package1 and Package2 have a column VoucherID and have to
be fetched based on the above condition. I can do it by below query using
Union or Union All, but please let me know if I can do it without using
UNion or Union All.
select P1.VoucherID from Payment P inner join Package1 P1 on
P1.empid=P.empid and P.PaymentTypeID=1
union all
select P2.VoucherID from Payment P inner join Package1 P2 on
P2.empid=P.empid and P.PaymentTypeID=3
Thanks, Krishna

No comments:

Post a Comment