PDA

View Full Version : getting highest id in table


bfsog
01-17-2005, 08:59 PM
I have a table with a column called id, set to autoincrement.
I have a admin section, on that page I want to see what the highest id is.

something like?

SELECT * id FROM table_name WHERE id = max ?

Thanks

Brandoe85
01-17-2005, 09:07 PM
Maybe:
SELECT id from tablename order by id DESC limit 1

raf
01-17-2005, 11:41 PM
other option:
select max(id) from tablename

but what do you wanna use it for :confused:

bfsog
04-19-2005, 10:29 AM
Just wanted to know how many rows are in table

NancyJ
04-19-2005, 11:04 AM
What if you delete a record? then the max id will not be the number of rows.

select count(*) FROM tablename

will tell you how many rows in the table

bfsog
04-19-2005, 03:06 PM
I thought my previous post might cause a stir, almost.

What I wanted was a way to say
the next post will be number $number

Thanks all.