sql - 使用 1 个 where 子句联合选择 2 个 SQL 表
问题描述
我有 2 张桌子Customer
和Product
. 我想将它组合到每个表的价格 > 1000 的结果集中。
但问题是我是否有办法为WHERE
the 使用 1 个子句,UNION
或者我需要为每个表创建一个子句。
例子:
SELECT ProductName, Customer, Price
FROM Customer
WHERE Price > 1000
UNION
SELECT ProductName, Company, Price
FROM Products
WHERE Price > 1000
ORDER BY Price
有没有办法让它看起来更像这样:
SELECT ProductName, Customer, Price
FROM Customer
UNION
SELECT ProductName, Company, Price
FROM Products
WHERE Price > 1000
ORDER BY Price
我从这个 SQL 中得到一个错误。
谢谢你的帮助。