How can I select the row with the highest ID in MySQL? This is my current code:
SELECT * FROM permlog WHERE max(id)
Errors come up, can someone help me?
How can I select the row with the highest ID in MySQL? This is my current code:
SELECT * FROM permlog WHERE max(id)
Errors come up, can someone help me?
For MySQL:
You want to sort the rows from highest to lowest
id
, hence theORDER BY id DESC
. Then you just want the first one soLIMIT 1
:Use this query to find the highest ID in the MySQL table.
SELECT MAX(id) FROM TABELNAME
This identifies the largest id and returns the value
if it's just the highest ID you want. and ID is unique/auto_increment:
This is the only proposed method who actually selects the whole row, not only the max(id) field. It uses a subquery
SELECT * FROM permlog WHERE id = ( SELECT MAX( id ) FROM permlog )
Suppose you have mulitple record for same date or leave_type but different id and you want the maximum no of id for same date or leave_type as i also sucked with this issue, so Yes you can do it with the following query: