SELECT [Unit UPC Base Item], [Item Description]
FROM (SELECT MIN([Item Description]) AS [Item Description], [Unit UPC Base Item]
FROM dbo.ItemDescLookups
GROUP BY [Unit UPC Base Item]) AS Sub
order by [Unit UPC Base Item] desc
SELECT MIN([Item Description]) AS [Item Description], [Unit UPC Base Item]
, MAX(CountofDescription) CountofDescription
FROM dbo.ItemDescLookups
GROUP BY [Unit UPC Base Item]
SELECT [Unit UPC Base Item], [Item Description]
FROM (SELECT Top 1([Item Description]) AS [Item Description], [Unit UPC Base Item]
FROM dbo.ItemDescLookups
GROUP BY [Unit UPC Base Item])
ORDER BY CountOfDescription DESC LIMIT 1
AS Sub
SELECT [Unit UPC Base Item], [Item Description]
FROM (SELECT MIN([Item Description]) AS [Item Description], [Unit UPC Base Item]
FROM dbo.ItemDescLookups
GROUP BY [Unit UPC Base Item]) AS Sub
When i try Min something 10 gets returned and when i try max something5 gets returned.CREATE VIEW VIEWName
AS
SELECT [Unit UPC Base Item],[Item Description],[CountOfDescription]
FROM
(
SELECT * , ROW_NUMBER() OVER ( PARTITION BY [Unit UPC Base Item] ORDER BY CountOfDescription DESC) rnk
FROM dbo.ItemDescLookups
)k WHERE rnk = 1
use MAX. - You need to use the MAX function to get the Maximum value from a COLUMN
Open in new window
Another option is you can use a ROW_NUMBER function.