2014-04-26 45 views
1

執行mysql查詢時,雖然只有單個條目存在於數據庫中,但會多次顯示記錄。這是爲什麼發生? 每當我執行查詢執行mysql查詢時,雖然數據庫中只存在單個條目,但多次顯示記錄

SELECT a.*, 
     b.CNTCT_ADD_ID AS Cntct_Add_Id, 
     c.PHONE_NBR_ID AS Cntct_nbr_Id, 
     d.OA_NM AS OaNm, 
     e.HOUSE_NAME AS house, 
     e.FLAT_NO AS flat, 
     e.HOUSE_NO AS houseno, 
     e.ADDRESS_LINE_1 AS Address1, 
     e.ADDRESS_LINE_2 AS Address2, 
     e.ADDRESS_LINE_3 AS Address3, 
     f.PHONE_NBR AS phneNO 
FROM contact_add_phoneno a 
LEFT JOIN contact_address b ON a.CNTCT_ADD_ID = b.CNTCT_ADD_ID 
LEFT JOIN contact_phones c ON a.CNTCT_NBR_ID = c.PHONE_NBR_ID 
LEFT JOIN org_accounts d ON a.OA_ID_ORIGINATED = d.OA_ID 
LEFT JOIN address_mst e ON e.ADDRESS_ID = b.ADD_ID 
LEFT JOIN phone_nbr_mst f ON f.PHONE_NBR_ID =c.PHONE_NBR_ID 

它顯示同一記錄的2倍以上。

回答

5

這是因爲加入。更改SELECTSELECT DISTINCT刪除重複的行。

+1

請記住,distinct關鍵字對查詢性能有很大影響。 – Vogel612

相關問題