Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to find the highest number in a mysql table

by sulfericacid (Deacon)
on May 10, 2008 at 00:53 UTC ( #685805=note: print w/ replies, xml ) Need Help??


in reply to How to find the highest number in a mysql table

my $data = qq(SELECT MAX(id) FROM table); # +1
or
my $data = qq(SELECT id FROM table ORDER BY id DESC); # +1


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid


Comment on Re: How to find the highest number in a mysql table
Select or Download Code
Re^2: How to find the highest number in a mysql table
by kyle (Abbot) on May 10, 2008 at 02:03 UTC

    There are a couple of problems here.

    The basic problem is that this only tells you what the last ID in the table was (+1), not what the next ID will be. If I insert a record and then delete it, that ID will not be reused, but your solution assumes it will. The next ID will actually be the highest +2. I could do this with any number of records.

    The other problem is in your second solution:

    my $data = qq(SELECT id FROM table ORDER BY id DESC); # +1

    This selects every row in the table. You really want to select only one:

    my $data = qq(SELECT id FROM table ORDER BY id DESC LIMIT 1); # +1

    ...but this still suffers from the first problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685805]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (20)
As of 2015-07-07 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls