RE: [PHP] Querying for MAX
| From: | Martin Towell | Date: | Wed, 12 Jun 2002 23:42:33 +0000 |
| Subject: | RE: [PHP] Querying for MAX | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-101837@lists.php.net to get a copy of this message | ||
what's you're after is
select max(id) from table
-----Original Message-----
From: David Freeman [mailto:dfreeman@outbackqld.net.au]
Sent: Thursday, June 13, 2002 9:36 AM
To: 'PHP General List'
Subject: RE: [PHP] Querying for MAX
> What I'm trying to do here is not inside PHP nor MySQL books
> I have. I need to query the DB to look the max result in a
> column. That is, if I have affiliate members with ID going
> from 1 to 10, get the query to know that the last member
> added was 10 so I can add member 11 without using
> auto_increment, because I need to insert old members too
> which already have ID numbers. Is that possible?
This is really a mysql question rather than a php question and would
probably be more appropriate to a mysql list. In any event, if you
seriously think auto_increment is not your solution here you probably
need to rethink your database design. This is exactly what
auto_increment is for. If someone is already in the list then you can
get their ID with a select and then do an update on their row, if
someone doesn't exist then you add them and ID auto_increments in the
process.
--
----------------------------------------------------------------------
Outback Queensland Internet ************************
Longreach ** New Web Site Online *
Queensland ************************
Australia W: www.outbackqld.net.au
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php