我有两个 MySQL 表:'invoice' 和 'credit_memo'
我想将它们结合起来并列出一个按日期排序的结果。
发票:
ID INT
日期 DATETIME
customer_id INT
credit_memo:
ID INT
日期 DATETIME
customer_id INT
我的最后尝试:
(SELECT ID AS invoice_number FROM invoice)
UNION
(SELECT ID AS credit_memo_number FROM credit_memo)
ORDER BY date
问题是 invoice_number 和 credit_memo_number 都被放入 invoice_number 变量中。因此,当我运行结果时,它看起来像是来自“发票”表。
如何确定每个特定行从哪个表中提取?
谢谢你,安迪