使用OR运算符连接两个表

时间:2012-08-09 20:52:31

标签: mysql sql visual-studio

如何编写将使用Or运算符连接两个表的查询 例如:

select upc,ean,productName
from maintable m1 left join maintable2 m2
on m2.upc = m1.upc OR m2.ean = m1.ean

1 个答案:

答案 0 :(得分:1)

好吧,你可以尝试使用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

这对你有用吗?默认情况下,UNION运算符只返回不同的行,因此不必担心返回重复项。