[PHP] Querying for MAX

2002-06-12 Thread César Aracena

I’m sorry if this mensaje is posted twice. I sent it yesterdays, but
then my ISP had problems with e-mail and I lost dozens of them and don’t
know if sent OK.


Hi all,

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?

Thanks in advance,


Cesar Aracena mailto:[EMAIL PROTECTED] 
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621





RE: [PHP] Querying for MAX

2002-06-12 Thread Lazor, Ed

select MAX(fieldname) from table;

You can also insert data in tables with auto_increment fields to account for
yourneed to insert old member ids.

insert into tablename (ID, Name) values ('$OldID', '$Name');



-Original Message-
From: César Aracena [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 12, 2002 11:36 AM
To: 'PHP DB List'; PHP General List
Subject: [PHP] Querying for MAX


I'm sorry if this mensaje is posted twice. I sent it yesterdays, but
then my ISP had problems with e-mail and I lost dozens of them and don't
know if sent OK.


Hi all,

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?

Thanks in advance,


Cesar Aracena mailto:[EMAIL PROTECTED] 
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621


 

This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.   

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Querying for MAX

2002-06-12 Thread Leotta, Natalie (NCI/IMS)

is

select MAX(column name)

what you are looking for?  I know it works on numeric columns, I'm not sure
if it works on non-numbers, you'd have to look it up in a SQL Tutorial
somewhere.

Good luck!

-Natalie

-Original Message-
From: César Aracena [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, June 12, 2002 2:36 PM
To: 'PHP DB List'; PHP General List
Subject: [PHP] Querying for MAX


I'm sorry if this mensaje is posted twice. I sent it yesterdays, but then my
ISP had problems with e-mail and I lost dozens of them and don't know if
sent OK.


Hi all,

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?

Thanks in advance,


Cesar Aracena mailto:[EMAIL PROTECTED] 
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Querying for MAX

2002-06-12 Thread César Aracena

Thanks Natalie  Ed. This Works just fine.

What I want to do, is let a person subscribe new affiliates without
having to look up what the last affiliate's number was and show the next
one in the new affiliate form.

César Aracena
IS / MCSE+I
Neuquén, NQN
(0299) 156-356688
(0299) 446-6621

 -Mensaje original-
 De: Leotta, Natalie (NCI/IMS) [mailto:[EMAIL PROTECTED]]
 Enviado el: Miércoles, 12 de Junio de 2002 03:39 p.m.
 Para: 'César Aracena'; 'PHP DB List'; PHP General List
 Asunto: RE: [PHP] Querying for MAX
 
 is
 
 select MAX(column name)
 
 what you are looking for?  I know it works on numeric columns, I'm not
 sure
 if it works on non-numbers, you'd have to look it up in a SQL Tutorial
 somewhere.
 
 Good luck!
 
 -Natalie
 
 -Original Message-
 From: César Aracena [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 12, 2002 2:36 PM
 To: 'PHP DB List'; PHP General List
 Subject: [PHP] Querying for MAX
 
 
 I'm sorry if this mensaje is posted twice. I sent it yesterdays, but
then
 my
 ISP had problems with e-mail and I lost dozens of them and don't know
if
 sent OK.
 
 
 Hi all,
 
 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?
 
 Thanks in advance,
 
 
 Cesar Aracena mailto:[EMAIL PROTECTED]
 CE / MCSE+I
 Neuquen, Argentina
 +54.299.6356688
 +54.299.4466621



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Querying for MAX

2002-06-12 Thread David Freeman



  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




RE: [PHP] Querying for MAX

2002-06-12 Thread Martin Towell

what's you're after is
select max(id) from table

-Original Message-
From: David Freeman [mailto:[EMAIL PROTECTED]]
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Querying for MAX

2002-06-12 Thread John Holmes

Just note that this will fail miserably unless you are locking your
tables around the SELECT MAX() and the INSERT. What if 3 different users
all select the same MAX() and try to insert the next number?

You really need to re-think your database design if you have to do it
this way.

---John Holmes...

 -Original Message-
 From: César Aracena [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 12, 2002 2:51 PM
 To: 'PHP DB List'; 'PHP General List'
 Subject: RE: [PHP] Querying for MAX
 
 Thanks Natalie  Ed. This Works just fine.
 
 What I want to do, is let a person subscribe new affiliates without
 having to look up what the last affiliate's number was and show the
next
 one in the new affiliate form.
 
 César Aracena
 IS / MCSE+I
 Neuquén, NQN
 (0299) 156-356688
 (0299) 446-6621
 
  -Mensaje original-
  De: Leotta, Natalie (NCI/IMS) [mailto:[EMAIL PROTECTED]]
  Enviado el: Miércoles, 12 de Junio de 2002 03:39 p.m.
  Para: 'César Aracena'; 'PHP DB List'; PHP General List
  Asunto: RE: [PHP] Querying for MAX
 
  is
 
  select MAX(column name)
 
  what you are looking for?  I know it works on numeric columns, I'm
not
  sure
  if it works on non-numbers, you'd have to look it up in a SQL
Tutorial
  somewhere.
 
  Good luck!
 
  -Natalie
 
  -Original Message-
  From: César Aracena [mailto:[EMAIL PROTECTED]]
  Sent: Wednesday, June 12, 2002 2:36 PM
  To: 'PHP DB List'; PHP General List
  Subject: [PHP] Querying for MAX
 
 
  I'm sorry if this mensaje is posted twice. I sent it yesterdays, but
 then
  my
  ISP had problems with e-mail and I lost dozens of them and don't
know
 if
  sent OK.
 
 
  Hi all,
 
  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?
 
  Thanks in advance,
 
 
  Cesar Aracena mailto:[EMAIL PROTECTED]
  CE / MCSE+I
  Neuquen, Argentina
  +54.299.6356688
  +54.299.4466621
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Querying for MAX -- solved

2002-06-12 Thread César Aracena

Come to think now, you are all right about making the field
auto_increment, instead of asking the DB which one is the following
number. It's just that I have a pretty large old DB in which this field
is NOT in sequence and should be imported before I keep designing the
scripts.

Thanks to all of you who helped me.

César Aracena
IS / MCSE+I
Neuquén, NQN
(0299) 156-356688
(0299) 446-6621

 -Mensaje original-
 De: John Holmes [mailto:[EMAIL PROTECTED]]
 Enviado el: Miércoles, 12 de Junio de 2002 08:51 p.m.
 Para: 'César Aracena'; 'PHP DB List'; 'PHP General List'
 Asunto: RE: [PHP] Querying for MAX
 
 Just note that this will fail miserably unless you are locking your
 tables around the SELECT MAX() and the INSERT. What if 3 different
users
 all select the same MAX() and try to insert the next number?
 
 You really need to re-think your database design if you have to do it
 this way.
 
 ---John Holmes...
 
  -Original Message-
  From: César Aracena [mailto:[EMAIL PROTECTED]]
  Sent: Wednesday, June 12, 2002 2:51 PM
  To: 'PHP DB List'; 'PHP General List'
  Subject: RE: [PHP] Querying for MAX
 
  Thanks Natalie  Ed. This Works just fine.
 
  What I want to do, is let a person subscribe new affiliates without
  having to look up what the last affiliate's number was and show the
 next
  one in the new affiliate form.
 
  César Aracena
  IS / MCSE+I
  Neuquén, NQN
  (0299) 156-356688
  (0299) 446-6621
 
   -Mensaje original-
   De: Leotta, Natalie (NCI/IMS) [mailto:[EMAIL PROTECTED]]
   Enviado el: Miércoles, 12 de Junio de 2002 03:39 p.m.
   Para: 'César Aracena'; 'PHP DB List'; PHP General List
   Asunto: RE: [PHP] Querying for MAX
  
   is
  
   select MAX(column name)
  
   what you are looking for?  I know it works on numeric columns, I'm
 not
   sure
   if it works on non-numbers, you'd have to look it up in a SQL
 Tutorial
   somewhere.
  
   Good luck!
  
   -Natalie
  
   -Original Message-
   From: César Aracena [mailto:[EMAIL PROTECTED]]
   Sent: Wednesday, June 12, 2002 2:36 PM
   To: 'PHP DB List'; PHP General List
   Subject: [PHP] Querying for MAX
  
  
   I'm sorry if this mensaje is posted twice. I sent it yesterdays,
but
  then
   my
   ISP had problems with e-mail and I lost dozens of them and don't
 know
  if
   sent OK.
  
  
   Hi all,
  
   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?
  
   Thanks in advance,
  
  
   Cesar Aracena mailto:[EMAIL PROTECTED]
   CE / MCSE+I
   Neuquen, Argentina
   +54.299.6356688
   +54.299.4466621
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php