Reputation: 97
How do i write a query that will join two tables using an Or operator For example:
select upc,ean,productName
from maintable m1 left join maintable2 m2
on m2.upc = m1.upc OR m2.ean = m1.ean
Upvotes: 0
Views: 202
Reputation: 452
Well, you can try using a UNION.
select upc,ean,productName
from maintable m1 left join maintable2 m2
on m2.upc = m1.upc
union
select upc,ean,productName
from maintable m11 left join maintable m22
on m22.ean = m11.ean
Does that work out for you? By default, the UNION operator will only return distinct rows, so do not worry about returning duplicates.
Upvotes: 1