Getting Latest/Top orderID for each customer in SQL Server -
i have database records orders of customers. i'm trying not orders of each customer, latest order customer made us. have using sub-select statement, because of how many data there is, taking alot of time retrieve. wondering there way around can speed up?
here's code of using sub-select statement i've written:
select customer.customerid, customer.firstname + ' ' + customer.surname [customer name], (select top(1) orders.orderid orders orders.customerid = customer.customerid order orders.orderid desc), (select top(1) orders.item orders orders.customerid = customer.customerid order orders.orderid desc) customer
any or info on how improve appreciated.
thanks
if there indexes created ,rebuilt/refresh indexes in increasing performance of query.
try creating non clustered indexes speed execution of query.
Comments
Post a Comment