Solved

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

Posted on 2004-09-20
7
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

738 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