0

I'm trying to figure out the highest id number (set to 'auto_increment') in my table, I tried

SELECT * FROM  `mytable` WHERE MAX( `id` )

but get

#1305 - FUNCTION xymplydb01.MAX does not exist 

Is there any other way how I can get this without using max? Thanks! Ron

BenR
  • 11,296
  • 3
  • 28
  • 47
stdcerr
  • 13,725
  • 25
  • 71
  • 128

2 Answers2

2

Use this syntax instead:

SELECT MAX(id) FROM mytable;
Michael Righi
  • 1,333
  • 9
  • 11
0

Shouldnt the MAX be in the select clause and not the where clause:

SELECT MAX('id') as id from 'mytable'

I didnt think using the MAX function in the where clause was valid.

Or if you want the row of data you could do a sub-query as well:

SELECT * 
FROM 'mytable' 
WHERE id=(
    SELECT max('id') FROM 'mytable'
) 

or without using MAX at all

Select * from 'mytable' order by 'id' desc limit 1

This would grab the largest id and only return that row.

jzworkman
  • 2,695
  • 14
  • 20