Quantcast
Channel: SQLServerCentral » SQL Server 2012 » SQL Server 2012 - T-SQL » Latest topics
Viewing all articles
Browse latest Browse all 4901

select top 1 row for each customer

$
0
0
Hi,I have customer table and order table and both consists of customerID columnwhich is primary key for customer table.I want to write a query which we will give all the recent order for each customer but restricting to the most recent order only.For Example:Customer Table:CustomerID 123Order TableOrderID CustomerID OrderDate Amount1 1 2012-11-27 3002 1 2012-11-28 3503 2 2012-11-28 400Result Set Needed:CustomerID OrderDate Amount1 2012-11-28 3502 2012-11-28 400NOTE: I need this T-SQL query without using CTE or Ranking Function like RANK(), ROW_NUMBER(),etc...Thank you in advance.

Viewing all articles
Browse latest Browse all 4901

Trending Articles