我有一個SQL查詢,我必須從兩個不同的表中獲取值(說a1,a2)。出於簡單的原因,它的工作原理,但因爲我有一個UNION在同一個查詢中有一個重要的原因(從表a2中獲取值放置在a1的列值之間),由於這個原因,我的查詢結果變得很奇怪。這是我的查詢和圖像,它顯示了同樣TICKET_ID的重複條目,我想刪除它,怎麼樣?在兩個表中顯示兩個表與一個UNION
QUERY
SELECT
RECEIPTS.DATENEW AS DATE,
TICKETS.TICKETID AS TICKETID,
PAYMENTS.PAYMENT AS PAYMENT,
PAYMENTS.TOTAL AS TOTAL,
CUSTOMERS.NAME AS NAME,
ADJUSTMENTS.ADJUSTMENT_REASON AS REASON
FROM RECEIPTS
INNER JOIN TICKETS ON RECEIPTS.ID = TICKETS.ID
INNER JOIN PAYMENTS ON RECEIPTS.ID = PAYMENTS.RECEIPT
INNER JOIN CUSTOMERS ON TICKETS.CUSTOMER = CUSTOMERS.ID
RIGHT JOIN ADJUSTMENTS ON ADJUSTMENTS.CUSTOMER_ID = CUSTOMERS.ID
WHERE
(PAYMENTS.PAYMENT = 'debt'
OR PAYMENTS.PAYMENT = 'debtpaid')
UNION SELECT
ADJUSTMENTS.DATE AS DATE,
ADJUSTMENTS.TICKET_NO AS TICKETID,
ADJUSTMENTS.ADJUSTMENT_TYPE AS PAYMENT,
ADJUSTMENTS.ADJUSTMENT_AMOUNT * -1 AS TOTAL,
ADJUSTMENTS.CUSTOMER_NAME AS NAME,
ADJUSTMENTS.ADJUSTMENT_REASON AS REASON
FROM ADJUSTMENTS
ORDER BY NAME ASC, DATE DESC
,這裏是它的輸出圖像
輸出
換另一個查詢各地工會,並用它來篩選受騙者? –
你會再詳細一點嗎? – Saqib