Jump to content

Archived

This topic is now archived and is closed to further replies.

sdat1333

Pulling The Ten Highest Integers From A Mysql Field

Recommended Posts

OK, there's a mysql db

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/

Share this post


Link to post
Share on other sites
is there going to be duplicate values in the column?

you can do something like this to get the top ten values:

[code]
SELECT var FROM table_name ORDER BY var ASC LIMIT 10
[/code]

and then you can use another query to grab the ID

[code]
SELECT var_id FROM table_name where var='$var'
[/code]

You can do this in one query with subselects but I think its easier to understand if you are new by using multiple queries.

Share this post


Link to post
Share on other sites
Wouldn't this be better?

[code]
SELECT var_id,var FROM table_name ORDER BY var DESC LIMIT 10
[/code]

Share this post


Link to post
Share on other sites
I was working under the assumption that it was 10 highest unique integers and all the IDs for those integers.

If its 10 integers and you will get more than 10 IDs, go with my code, otherwise go with wildbugs

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.