Select last 5 rows in join query SQL Server 2008 -
i trying bring last 5 rows of order
table based on orderdate
column name firstname
customer
table.
the below query displays values order
table instead of last 5 rows.
select a.[firstname], b.[orderid], b.[orderdate], b.[totalamount], b.[orderstatusid] [schema].[order] b outer apply (select top 5 * [schema].[customer] b.[customerid] = 1 , a.[customerid] = b.[customerid] order b.[orderdate] desc)
any mistake in logic of using top
, desc
?
if want last 5 rows of order
table, why apply top
customer
table?
select top 5 a.[firstname],b.[orderid],b.[orderdate],b.[totalamount],b.[orderstatusid] [schema].[order] b left join [schema].[customer] on a.[customerid]=b.[customerid] b.[customerid]=1 order b.[orderdate] desc
Comments
Post a Comment