2015-03-02 152 views
-1

下面的查詢工作,但它給了我同樣的數據多次.... 建議我上懸而未決這個MYSQL與內部查詢結果加入

"SELECT 
    cp.projectID,cp.projectName,cp.clientID, 
    pv.vendorID, 
    cv.vendorName, 
    c.clientName, 
    vp.productName, 
    pp.sku 
FROM clientProjects AS cp 
    INNER JOIN clients AS c ON c.clientID = cp.clientID 
    INNER JOIN projectVendors AS pv ON cp.projectID = pv.projectID 
    INNER JOIN clientVendors AS cv ON cv.vendorID = pv.vendorID 
    INNER JOIN projectProducts AS pp ON cp.projectID = pp.projectID 
    INNER JOIN projectMaintenance AS pm ON cp.projectID = pm.projectID 
    INNER JOIN vendorProducts AS vp ON pp.sku = vp.sku 
    INNER JOIN projectFiles AS pf ON cp.projectID = pf.projectID 
WHERE cp.projectName LIKE '".$projectName."' OR c.clientName LIKE '".$projectName."' OR pp.sku LIKE '".$projectName."' OR pm.sku LIKE '".$projectName."' " 
+0

試組關鍵字 – 2015-03-02 09:04:44

+0

使用不同或分組以避免冗餘。 – 2015-03-02 09:04:58

+0

http://stackoverflow.com/questions/7084577/removing-duplicates-from-sql-join – Styl 2015-03-02 09:06:01

回答

0

嘗試DISTINCT:由

SELECT DISTINCT cp.projectID, 
       cp.projectName, 
       cp.clientID, 
       pv.vendorID, 
       cv.vendorName, 
       c.clientName, 
       vp.productName, 
       pp.sku 
FROM clientProjects AS cp 
INNER JOIN clients AS c ON c.clientID = cp.clientID 
INNER JOIN projectVendors AS pv ON cp.projectID = pv.projectID 
INNER JOIN clientVendors AS cv ON cv.vendorID = pv.vendorID 
INNER JOIN projectProducts AS pp ON cp.projectID = pp.projectID 
INNER JOIN projectMaintenance AS pm ON cp.projectID = pm.projectID 
INNER JOIN vendorProducts AS vp ON pp.sku = vp.sku 
INNER JOIN projectFiles AS pf ON cp.projectID = pf.projectID 
WHERE cp.projectName LIKE '".$projectName."' OR 
     c.clientName LIKE '".$projectName."' OR 
     pp.sku LIKE '".$projectName."' OR 
     pm.sku LIKE '".$projectName."' " 
+0

感謝其現在的工作... – user3274951 2015-03-02 09:14:21