Re: First and Last ID of a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sounds about right... you can also do something like this (syntax should be right):

SELECT MIN(id) as minid, MAX(id) as maxid FROM mytable


$array['minid'] and $array['maxid']


Basically it's going to be whatever the heading of that column is.  Using "as" gives it an alias for less ugly headings.

If you did SELECT COUNT(Qty) FROM SomeTable

Then you might get:

$array['Count of Qty'] or something goofy like that.  I forget the exact circumstances but there's times you get goofy stuff like that.

If you run the SQL through some DB client (like mysql's command line stuff or I use WinSQL Lite in Windows to connect to our MySQL database across the network) you can usually see what the heading name is going to end up being, if you don't explicitly set it with an "AS" clause.

"AS" also works on table names:

SELECT l.LeadID, ld.FirstName FROM Leads as l, LeadData as ld
WHERE l.LeadID = ld.LeadID

(actually a lot of the time you can leave out the "as" and just do "Leads l")

Fun times..

-TG


= = = Original message = = =

<tg-php@xxxxxxxxxxxxxxxxxxxxxx> wrote in message 
news:20070711201352.905EE10A008@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> SELECT MIN(id), MAX(id) FROM mytable

As an aside, is you are using associative arrays, be sure to use the 
following keys:

$array['MIN(id)'] and $array['MAX(id)']

Just something I figured out recently :)

Matt 

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


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux