blog.x-e.ro / SQL get last ID : mssql and mysql

SQL get last ID

sql :: mssql and mysql

here's a simple SQL script that returns the last row created. this is great for when you add a new record that has an autogenerated id and you need that number.

mssql

CREATE PROCEDURE [dbo].[getLastLogin]
AS
SELECT TOP 1 *
FROM dbo.login
ORDER BY id DESC
GO

mysql

SELECT * FROM `login` 
ORDER BY `id` DESC
LIMIT 1,1;
loading...

loading...