[英]How to see all data from one table and filtered on another, when using a join query (oracle sql)
一旦我执行拆分,我希望看到以下 3 件事:
除了第 2 点之外,我在下面的查询获得了大部分权利,因为它只返回事务 5 和 6 而不是完整列表。 我能改变什么?
SELECT * FROM customers c
INNER JOIN transactions t ON c.custid = t.custid
INNER JOIN purchaces p ON t.transid = p.transid
WHERE c.customer = 1234 AND t.trans_num IN (5,6)
ORDER BY t.trans_num
您在 where 语句中明确过滤记录 5 和 6。 您可以使用该条件 LEFT JOIN 购买表。 您将获得所有交易,但如果购买列不属于交易 5 或 6,则它们将为 NULL。
SELECT *
FROM customers c
INNER JOIN transactions t
ON c.custid = t.custid
LEFT JOIN purchaces p
ON t.transid = p.transid
AND t.trans_num IN (5,6)
WHERE c.customer = 1234
ORDER BY t.trans_num
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.