• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Select distinct (only one column - and not the first one)

I have the following query:

SELECT "MOT-" & [Moteng_Inventory]![sku] AS sku, IIf(IsNull(DLookUp("[sku]","Moteng Errors","[sku] = '" & [Moteng_Inventory]![sku] & "'")),[Moteng_Inventory]![UPC], DLookUp("[ASIN]","Moteng Errors","[sku] = '" & [Moteng_Inventory]![sku] & "'")) AS [standard-product-id], IIf(IsNull(DLookUp("[SKU]","Moteng Errors","[sku] = '" & [Moteng_Inventory]![sku] & "'")),"UPC","ASIN") AS [product-id-type], Moteng_Inventory.title, Moteng_Template.Brand, Moteng_Inventory.brand, Moteng_Template.ManufacturerPartNumber, Moteng_Template.BulletPoint1, Moteng_Template.BulletPoint2, Moteng_Template.BulletPoint3, Moteng_Template.BulletPoint4, Moteng_Template.BulletPoint5, Moteng_Template.ProductDescription, Moteng_Template.Prop65, Moteng_Template.LegalDisclaimer, Moteng_Template.Memorabilia, Moteng_Template.Autographed, Moteng_Template.ItemType, Moteng_Template.UsedFor1, Moteng_Template.UsedFor2, Moteng_Template.UsedFor3, Moteng_Template.UsedFor4, Moteng_Template.UsedFor5, Moteng_Template.TargetAudience1, Moteng_Template.TargetAudience2, Moteng_Template.TargetAudience3, Moteng_Template.OtherItemAttributes1, Moteng_Template.OtherItemAttributes2, Moteng_Template.OtherItemAttributes3, Moteng_Template.OtherItemAttributes4, Moteng_Template.OtherItemAttributes5, Moteng_Template.SubjectContent1, Moteng_Template.SubjectContent2, Moteng_Template.SubjectContent3, Moteng_Template.SubjectContent4, Moteng_Template.SubjectContent5, Moteng_Template.SearchTerm1, Moteng_Template.SearchTerm2, Moteng_Template.SearchTerm3, Moteng_Template.SearchTerm4, Moteng_Template.SearchTerm5, Moteng_Template.PlatinumKeyword1, Moteng_Template.PlatinumKeyword2, Moteng_Template.PlatinumKeyword3, Moteng_Template.PlatinumKeyword4, Moteng_Template.PlatinumKeyword5, Moteng_Template.MainImageURL, Moteng_Template.SwatchImageURL, Moteng_Template.PackageLengthUnitOfMeasure, Moteng_Template.PackageLength, Moteng_Template.PackageWidth, Moteng_Template.PackageHeight, Moteng_Template.PackageWeightUnitOfMeasure, IIf(Format([Moteng_Inventory]![misc1],'.00')<1,"1.00",Format([Moteng_Inventory]![misc1],'.00')) AS Expr1, Moteng_Template.AgeGenderCategory, Moteng_Template.BikeRimSize, Moteng_Template.Color, Moteng_Template.Curvature, Moteng_Template.DivingHoodThickness, Moteng_Template.Flavor, Moteng_Template.GolfFlex, Moteng_Template.GolfLoft, Moteng_Template.GripSize, Moteng_Template.Hand, Moteng_Template.HeadSize, Moteng_Template.Length, Moteng_Template.LengthUnitOfMeasurement, Moteng_Template.LineCapacity, Moteng_Template.LineWeight, Moteng_Template.Material, Moteng_Template.Packaging, Moteng_Template.PackageQuantity, Moteng_Template.ShaftMaterial, Moteng_Template.ShaftType, Moteng_Template.Size, Moteng_Template.Weight, Moteng_Template.WeightUnitOfMeasurement, Moteng_Template.WeightSupported, Moteng_Template.Parentage, Moteng_Template.ParentSKU, Moteng_Template.RelationshipType, Moteng_Template.VariationTheme, Moteng_Template.ProductTaxCode, Moteng_Template.LaunchDate, Moteng_Template.MAP, IIf([Moteng_QTY]![cost]<10,Format([Moteng_QTY]![cost]/0.87*1.15+4,'.00'),Format([Moteng_QTY]![cost]/0.87*1.15+1,'.00')) AS price, Moteng_Template.SalesPrice, Moteng_Template.SaleStartDate, Moteng_Template.SaleEndDate, Moteng_Template.ConditionType, IIf([Moteng_QTY]![qty]<6,0,[Moteng_QTY]![qty]) AS qty, Moteng_Template.[leadtime-to-ship], Moteng_Template.IsGiftMessageAvailable, Moteng_Template.IsGiftWrapAvailable, Moteng_Template.UpdateDelete, Moteng_Template.Field96, Moteng_Template.Field97, Moteng_Template.Field98, Moteng_Template.Field99, Moteng_Template.Field100, Moteng_Template.Field101, Moteng_Template.Field102, Moteng_Template.Field103, Moteng_Template.Field104, Moteng_Template.Field105, Moteng_Template.Field106, Moteng_Template.Field107, Moteng_Template.Field108, Moteng_Template.Field109, Moteng_Template.Field110, Moteng_Template.Field111, Moteng_Template.Field112, Moteng_Template.Field113, Moteng_Template.Field114, Moteng_Template.Field115, Moteng_Template.Field116, Moteng_Template.Field117, Moteng_Template.Field118, Moteng_Template.Field119, Moteng_Template.Field120, Moteng_Template.Field121, Moteng_Template.Field122, Moteng_Template.Field123, Moteng_Template.Field124, Moteng_Template.Field125, Moteng_Template.Field126, Moteng_Template.Field127, Moteng_Template.Field128, Moteng_Template.Field129, Moteng_Template.Field130, Moteng_Template.Field131, Moteng_Template.Field132, Moteng_Template.Field133, Moteng_Template.Field134, Moteng_Template.Field135, Moteng_Template.Field136, Moteng_Template.Field137, Moteng_Template.Field138
FROM Moteng_Template, Moteng_Eliminate_Bad_UPCs INNER JOIN (Moteng_Inventory INNER JOIN Moteng_QTY ON Moteng_Inventory.sku = Moteng_QTY.sku) ON Moteng_Eliminate_Bad_UPCs.upc = Moteng_Inventory.upc
WHERE (((IIf([Moteng_QTY]![cost]<10,Format([Moteng_QTY]![cost]/0.87*1.15+4,'.00'),Format([Moteng_QTY]![cost]/0.87*1.15+1,'.00')))<>0));

I can't figure out how to select ONLY DISTINCT RECORDS FOR THE STANDARD-PRODUCT-ID FIELD.  Simply adding "distinct" after select won't work because the data in the previous field is different...your help is greatly appreciated.
0
jimday1982
Asked:
jimday1982
  • 3
  • 2
1 Solution
 
wblakelyCommented:
If the data in the previous field is different, then by definition the record is distinct.  The uniqueness of each record returned by your query is determined by the values of every column.
0
 
jimday1982Author Commented:
That makes sense and I understand that, but my problem (and I know this is out of the ordinary) is that I need to make sure that field (UPC), and only that field, has no duplicates - is this possible?
0
 
wblakelyCommented:
If it does have duplicates what would you do with them? flag them? exclude them from the query result?

To do either, you could run a summary query ("UPCSumary") with a count of UPC ("CountOfUPC") per [standard-product-id] field and link the summary query on [standard-product-id] to your query above.  Then, exclude or flag (whichever you choose) where UPCSummary.CountOfUPC > 1
0
 
jimday1982Author Commented:
That sounds like an idea - can you provide info on creating a summary query?
0
 
wblakelyCommented:
Here's a sample summary using your data as I understand it.

SELECT IIf(IsNull(Errors!sku),Inventory!UPC,Errors!ASIN) AS [standard-product-id], Count(Inventory.upc) AS CountOfUPC
FROM Moteng_Inventory AS Inventory LEFT JOIN [Moteng Errors] AS Errors ON Inventory.sku = Errors.sku
GROUP BY IIf(IsNull(Errors!sku),Inventory!UPC,Errors!ASIN);

Just shorten the SQL, I've used alias names for your tables (e.g. "Moteng_Inventory AS Inventory").
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now