Search code examples
sqlleft-joinzoho

SQL Join resulting in multiple duplicate entries


I'm having troubles figuring out how to get rid of the dupes from the first table. please see highlighted rows here for reference enter image description here

This is the formaula I'm inputting

SELECT
     "Classes.Class Name" AS Customer,
     "Customers.Customer Name" as docket,
     "Items.Item Name" as EST_Item,
     Quantity as EST_Qty,
     "Unit Price" as EST_UnitPrice,
     "Query_Bill Line items"."Items.Item Name" as BILL_Item,
     "Query_Bill Line items"."Quantity" as Bill_Qty,
     "Query_Bill Line items"."Unit Price" as Bill_UnitPrice
FROM  "Query_Estimate Line Items" LEFT JOIN "Query_Bill Line Items" ON "Query_Estimate Line Items"."cUSTOMERS.cUSTOMER NAME"  = "Query_Bill Line Items"."CUSTOMERS.CUSTOMER NAME"
 AND    "Query_Estimate Line Items"."iTEMS.ITEM NAME"  = "Query_Bill Line Items"."ITEMS.ITEM NAME"  

Sorry for the super long column names! What am I missing to get rid of the dupes from Table1 ""Query_Estimate Line Items"?

Thanks


Solution

  • To reduce your row count you need to group by something (such as Customer, Docket, EST_Item), and aggregate your non-grouped columns (such as Bill_Qty or Unit_Price). Do you know how to use group by?