Jump to content

Pulling The Ten Highest Integers From A Mysql Field


sdat1333

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/
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.