Working in phpMyAdmin for now:
order table strucure:
OrderID int(11) auto_increment
CustomerID varchar(50)
BillAddr varchar(200)
ShipAddr varchar(200)
Date date
Total double
The table currently has 4 rows of data, with different OrderIDs.
SQL:
SELECT LAST_INSERT_ID() FROM `order`
Result:
LAST_INSERT_ID()
0
0
0
0
I was expecting the fourth rows OrderID – just one number but got a 0 for each row in phpMyAdmin.
LAST_INSERT_ID()returns the id of the last inserted row and is not bound to any table. So if you create a new row:It will return the last id (whatever value the new primary key has).
For details, please take a look at the manual:
If you just want to get last ID in a table, you can do it like this: