Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select the row with the highest ID in MySQL?

Tags:

mysql

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?

like image 985
user870380 Avatar asked Jul 30 '11 06:07

user870380


People also ask

How do I select the highest number in MySQL?

You can use ORDER BY clause or aggregate function MAX() to select the maximum value.

How do you find the highest value in a row in SQL?

To find the maximum value of a column, use the MAX() aggregate function; it takes a column name or an expression to find the maximum value. In our example, the subquery returns the highest number in the column grade (subquery: SELECT MAX(grade) FROM student ).


2 Answers

SELECT * FROM permlog ORDER BY id DESC LIMIT 0, 1 
like image 187
badbod99 Avatar answered Oct 24 '22 05:10

badbod99


if it's just the highest ID you want. and ID is unique/auto_increment:

SELECT MAX(ID) FROM tablename 
like image 43
TD_Nijboer Avatar answered Oct 24 '22 06:10

TD_Nijboer