views:

500

answers:

3

Hi 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 .

+8  A: 
SELECT id
FROM table
ORDER BY id DESC
LIMIT 1
Quassnoi
+10  A: 

SELECT MAX(id) FROM table

Vegard Larsen
+1  A: 

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.

Alex Barrett