Bek-7777
Bek-7777

Reputation: 13

To know last insert data on mysql

I have some questions about syntax on mysql. Is it possibly to know last insert data on mysql with sql command in terminal or not? If possibly just write me thanks for all hints.

Upvotes: 1

Views: 61

Answers (3)

The Hungry Dictator
The Hungry Dictator

Reputation: 3484

You can use this:

$sql = 'SELECT user_id FROM my_users_table ORDER BY user_id DESC LIMIT 0,1';

Upvotes: 1

Martin Nuc
Martin Nuc

Reputation: 5764

You can get last inserted ID using LAST_INSERT_ID()

Reference: http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

Upvotes: 1

VancleiP
VancleiP

Reputation: 657

insert into table (field) values (value);
SELECT @iLastId := LAST_INSERT_ID();

Upvotes: 2

Related Questions