Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT TOP 1 * FROM table_Name ORDER BY unique_column DESC


What will be the result:
- last inserted one or
- first one ?

I need last inserted CustomerID.
Posted
Updated 15-Sep-15 22:06pm
v2
Comments
Awadhendra Tripathi 16-Sep-15 2:37am    
Yes it will give you last inserted column.
tiFoysal 16-Sep-15 2:58am    
thanks a lot
Mehdi Gholam 16-Sep-15 2:38am    
This is SQL not vb.net
tiFoysal 16-Sep-15 2:57am    
ohhh yeah you r right..sorry... and thanks for that. :)

The query explains itself, it returns the whole top row of table_Name ordered, descending, by unique_column. This way you'll get the row having the greatest value of unique_column. If you are inserting unique_column incrementally then, yes, you'll get the last inserted one.

Out of curiosity, why don't you try it?
 
Share this answer
 
Comments
tiFoysal 16-Sep-15 3:44am    
i just taking the backup of database from live server to local
last inserted one will be your output
 
Share this answer
 
Hi,

Check this...

Order By[^]

Hope this will help you.


Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900