具有内部联接的MYSQL查询结果

时间:2023-02-02 16:38:26

Below query is working but it gives me same data multiple times.... suggest me to slove this

下面的查询是有效的,但它给了我多次相同的数据....建议我解决这个问题

"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."' "

1 个解决方案

#1


0  

Try 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."' "

#1


0  

Try 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."' "