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

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

example: -

id   Value
1    david
2    jone
3    chris

I need a return 3 function if this table exists.

+5
source share
5 answers

If you want to select the identifier of the last inserted row in the table with the AUTO_INCREMENT column, you will be interested to know MySQL LAST_INSERT_ID .

+9
source

You can use:

SELECT MAX(id) FROM table
+15
source
SELECT id
FROM table
ORDER BY id DESC
LIMIT 1
+9

::

 $lastId = mysql_insert_id();
-1
SELECT * FROM table ORDER BY id DESC LIMIT 1
-2

All Articles