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

  1. if there indexes created ,rebuilt/refresh indexes in increasing performance of query.

  2. try creating non clustered indexes speed execution of query.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -