Quantcast
Channel: DISTINCT on one column and return TOP rows - Database Administrators Stack Exchange
Browsing latest articles
Browse All 4 View Live

Answer by Jonathan Roberts for DISTINCT on one column and return TOP rows

I think this could be more efficient that the other solutions, provided you have an index on: (Customer_Name, Purchase_Cost DESC) INCLUDE (Order_No);WITH PurchaseTable AS( SELECT * FROM (VALUES...

View Article



Answer by Fatih for DISTINCT on one column and return TOP rows

please try:SELECT DISTINCT TOP 3 order_no, customer_name, Purchase_CostFROM( SELECT order_no, customer_name, Purchase_Cost, ROW_NUMBER() OVER(PARTITION BY customer_name ORDER BY Purchase_Cost DESC)...

View Article

Answer by SqlWorldWide for DISTINCT on one column and return TOP rows

Replace your dbname and schemaName in the following query.;WITH CTE AS (SELECT [Order_No] ,[Customer_Name] ,[Purchase_Cost] , ROW_NUMBER() OVER(PARTITION BY [customer Name] ORDER BY [Purchase Cost]...

View Article

Image may be NSFW.
Clik here to view.

DISTINCT on one column and return TOP rows

How do you query for three unique customers with the largest Purchase_Cost?I want to apply the DISTINCT only on Customer_Name, but the query below applies the distinct on all three columns. How should...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images