Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last field in a Mysql database with PHP?

I have mysql database and I want to get the last ID from field in a table .

example : -

id   Value
1    david
2    jone
3    chris

I want a function return 3 if this table exist .

like image 778
Waseem Avatar asked Feb 20 '09 17:02

Waseem


3 Answers

You can use:

SELECT MAX(id) FROM table
like image 64
Vegard Larsen Avatar answered Nov 15 '22 04:11

Vegard Larsen


If you want to select the ID of the most recently inserted row in a table with an AUTO_INCREMENT column, you will likey be interested in MySQL's LAST_INSERT_ID function.

like image 30
Alex Barrett Avatar answered Nov 15 '22 04:11

Alex Barrett


SELECT id
FROM table
ORDER BY id DESC
LIMIT 1
like image 45
Quassnoi Avatar answered Nov 15 '22 02:11

Quassnoi