We help IT Professionals succeed at work.

sql server query to create an access query that will only result in 1 distinct combination

Fordraiders
Fordraiders asked
on
Access: 2010
What I have:   sql server query that creates a unique


What I need:
I need to create a query that will find distinct and unique combination of 2 fields

Current sql server query:  I NEED THIS QUERY TO RESULT THE SAME IN ACCESS


SELECT MIN(SKU) AS SKU
       ,[CompSKUCondensed]
       ,[VdrBrandName]
       ,COUNT([sku]) AS [Count]
   FROM [QA].[dbo].[comp_aio_bkp_vsm]
   WHERE SKU > '' and [CompSKUCondensed] > '' and [VdrBrandName] > '' and
         XRef_Comment NOT IN ('PARENT CHILD CROSSES', 'BRAND XREFS FROM 1 TO 16','BRAND FROM 1 TO 16')
   GROUP BY  
        [VdrBrandName]
   ,[CompSKUCondensed]
   HAVING COUNT(SKU) = 1
   ORDER BY [CompSKUCondensed]


Thanks
fordraiders
Comment
Watch Question

What you have there is fairly close to what you'd need. The WHERE statement will need some work I suspect, but not sure what you're trying to achieve with that.


Kelvin
EE Topic Advisor
Most Valuable Expert 2014
Awarded 2013
Commented:
SELECT
      MIN( SKU ) AS SKU
    , [CompSKUCondensed]
    , [VdrBrandName]
    , COUNT( [sku] ) AS [CountOf]
FROM your_table_here
WHERE (SKU > '')
AND ([CompSKUCondensed] > '')
AND ([VdrBrandName] > '')
AND (XRef_Comment NOT IN ('PARENT CHILD CROSSES', 'BRAND XREFS FROM 1 TO 16', 'BRAND FROM 1 TO 16'))
GROUP BY
         [VdrBrandName]
       , [CompSKUCondensed]
HAVING COUNT( SKU ) = 1
ORDER BY [CompSKUCondensed]

Open in new window


Access seems likes parentheses which can be painful (IMO) but aside from the table name the query looks as if it will work pretty much as is

In SQL Server you can use that having clause without including that column in the select clause, not sure about Access.

COUNT(SKU) as [Count] -- I don't recommend using reserved words so I used [CountOf]
&
you could use COUNT(*) for the same calculation

or, you might be after COUNT( DISTINCT SKU ) perhaps?

Author

Commented:
thanks