我想知道是否可以在不使用LEFT JOIN
的情况下模拟JOINs
。
我使用this database并尝试使用JOIN
模拟此SELECT
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
我目前只能获得INNER JOIN
。这是我目前的查询:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID=Orders.CustomerID
ORDER BY CustomerName;
答案 0 :(得分:2)
您可以添加左反连接查询,例如:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID=Orders.CustomerID
ORDER BY CustomerName
UNION
SELECT Customers.CustomerName, NULL FROM Customers
WHERE Customers.CustomerID NOT IN (SELECT CustomerID FROM Orders);