Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 01-17-2005, 08:59 PM   PM User | #1
bfsog
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
bfsog is an unknown quantity at this point
getting highest id in table

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
bfsog is offline   Reply With Quote
Old 01-17-2005, 09:07 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,435
Thanks: 2
Thanked 38 Times in 38 Posts
Brandoe85 will become famous soon enough
Maybe:
SELECT id from tablename order by id DESC limit 1
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 01-17-2005, 11:41 PM   PM User | #3
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf is on a distinguished road
other option:
select max(id) from tablename

but what do you wanna use it for
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Old 04-19-2005, 10:29 AM   PM User | #4
bfsog
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
bfsog is an unknown quantity at this point
Just wanted to know how many rows are in table
bfsog is offline   Reply With Quote
Old 04-19-2005, 11:04 AM   PM User | #5
NancyJ
Senior Coder

 
NancyJ's Avatar
 
Join Date: Feb 2005
Location: Bradford, UK
Posts: 3,051
Thanks: 14
Thanked 61 Times in 60 Posts
NancyJ will become famous soon enough
What if you delete a record? then the max id will not be the number of rows.

Code:
 select count(*) FROM tablename
will tell you how many rows in the table
NancyJ is offline   Reply With Quote
Old 04-19-2005, 03:06 PM   PM User | #6
bfsog
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
bfsog is an unknown quantity at this point
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.
bfsog is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:58 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.