Pulling The Ten Highest Integers From A Mysql Field
Posted 28 June 2006 - 10:49 PM
One field will be occupied with integers. I want the system to sort the ten greatest fields in an array or something. Then I need a way to pull the 'id num' (an incremented field) associated with each of the 10 highest integers from that column.
Ideas? Sorry if this is a really easy task, I'm new to PHP/MySQL
Also, if theres an easy way to do this using ADOdb that would be preferred (I would like to keep server CPU load down as much as possible, and ADOdb caches previous queries to reduce load.
Detailed instructions would be helpful, I'm a HUGE PHP/MySQL noob. So please don't assume too much knowledge/
Posted 30 June 2006 - 03:39 PM
you can do something like this to get the top ten values:
SELECT var FROM table_name ORDER BY var ASC LIMIT 10
and then you can use another query to grab the ID
SELECT var_id FROM table_name where var='$var'
You can do this in one query with subselects but I think its easier to understand if you are new by using multiple queries.
Posted 30 June 2006 - 06:24 PM
SELECT var_id,var FROM table_name ORDER BY var DESC LIMIT 10
Posted 30 June 2006 - 06:26 PM
If its 10 integers and you will get more than 10 IDs, go with my code, otherwise go with wildbugs
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users