MS SQL tutorial showing how to return the latest record from a table

preview_player
Показать описание
This is a Microsoft SQL tutorial showing how to get the latest record from a table. This tutorial includes nested selects. The example in the video is how to get the latest sales record for each customer.

Complimentary videos:
Рекомендации по теме
Комментарии
Автор

In my system (zoho analytics) can't do that, but I saved the query and then created a new one and I take the values from there, but when I try to obtain other data like the amount, and I join by customer ID, duplicates everything because I have more the one customer ID, since there's more the one sales order. How can I fix that? Thank you for your video.

mariansweetheart
Автор

I have a list of orders. Each time the status is updated for the order, the order duplicates with the latest date (ex. Order 7887 opened on 11/6, order 7887 closed on 11/8)

Do use the MAX() on the date or the order number itself to find the latest update for that Order?

takaKizne
Автор

What if I want to see orders processed after 2012? Can I just use Where ns.OrderDate>='2012-01-01'?

pujanparvadia
Автор

thank u for your tutorial. i have any problem to take data with new date.

i use this query. and work

select *
from(
select nama, max(tanggal) MAXID
from tester.dataku group by nama)ns
inner join tester.dataku on (dataku.tanggal=ns.MAXID and dataku.nama=ns.nama)

I develop from your query to my table.

agustriyono