[英]How to see all data from one table and filtered on another, when using a join query (oracle sql)
Once I execute split, im hoping to see the following 3 things:一旦我执行拆分,我希望看到以下 3 件事:
My query below gets most of this right except for point 2, as it only returns transactions 5 and 6 instead of the full list.除了第 2 点之外,我在下面的查询获得了大部分权利,因为它只返回事务 5 和 6 而不是完整列表。 What can I change?
我能改变什么?
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
You are explicitely filtering for records 5 and 6 in your where statement.您在 where 语句中明确过滤记录 5 和 6。 You can LEFT JOIN the purchases table using that condition.
您可以使用该条件 LEFT JOIN 购买表。 You will get all transactions, but the purchases columns will be NULL if they don't belong to transactions 5 or 6.
您将获得所有交易,但如果购买列不属于交易 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.