Solved

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

Posted on 2004-09-20
7
239 Views
Last Modified: 2012-06-27
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
Comment
Question by:jimday1982
  • 3
  • 2
7 Comments
 
LVL 2

Expert Comment

by:wblakely
ID: 12102152
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
 

Author Comment

by:jimday1982
ID: 12102181
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
 
LVL 2

Expert Comment

by:wblakely
ID: 12102267
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
 

Author Comment

by:jimday1982
ID: 12102341
That sounds like an idea - can you provide info on creating a summary query?
0
 
LVL 2

Accepted Solution

by:
wblakely earned 125 total points
ID: 12102738
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now