I have this item table stored in SQL Server database:
ID_Item | ID_Sale | ID_Product |
1 | 200 | 2314 |
2 | 200 | 3894 |
3 | 200 | 4949 |
4 | 100 | 9389 |
5 | 100 | 9499 |
6 | 300 | 9388 |
And I need get the last record of the “ID_Sale” column. Those records as follow:
ID_Item | ID_Sale | ID_Product |
3 | 200 | 4949 |
5 | 100 | 9499 |
6 | 300 | 9388 |
I am trying this code, but it fetches only one record:
Select Top 1 * From Itens
Where ID_Sale = 200
Order by ID_Item Desc
How to get the results iterating over the entire table?
If you use SQL SERVER 2005+