Re: DESC order results

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

 



Danny Brow schreef:
Just wondering if anyone could tell me how reliable the DESC order
option is going to be when I am parsing thousands of records where they
are multiple ChartNo's for the same clientNo. Or is there a better way
to grab the most recent ChartNo.

this is a mysql question not a php question, please try to ask questions
in the appropriate forum.

the reliability of 'ORDER BY' is not tied to the ammount of
records returned.

given that you only want the 'most recent'
(by which I assume you mean the 'highest value') ChartNo for
a given clientNo you should be performing a query that returns a
single row of data.

also you shouldn't be quoting values pertaining to numeric fields
(I assume clientNo is an integer)

1. assuming ChartNo is numeric:

SELECT MAX(ChartNo) as chartno FROM eChart WHERE clientNo=2

2. assuming ChartNo is a varchar (or similar):

SELECT ChartNo FROM eChart WHERE clientNo=2 ORDER BY ChartNo DESC LIMIT 0,1


$link = mysql_connect('localhost', 'myuser', 'mypassword') or die('Could
not connect: ' . mysql());

mysql_select_db('mydatabase') or die('Could not select database');

$query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo
DESC';

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$line = mysql_fetch_array($result, MYSQL_ASSOC);


// Just for testing....
print mysql_num_rows($result);



Thanks,
Dan





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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux