Jump to content

select least number


searls03

Recommended Posts

I am trying to run two queries within one I guess you could say.  What I am trying to do is build a scoring system where each person gets two chances.  The least number is their best.  What I need to have happen is for the php query to select the smallest number for each person, then display the 3 names of the people with the 3 smallest numbers.

 

I am guessing I need to use a query like this to get the smallest number for each person:

$sql = mysql_query("SELECT LEAST(MIN(COL1),MIN(COL2))FROM yourtable;");

but after this I am stumped as to how to make it display the names associated with the 3 smallest numbers.  

 

Can anyone help me out?

Link to comment
Share on other sites

but after this I am stumped as to how to make it display the names associated with the 3 smallest numbers. 

 

For this part, you did not provide the necessary information. Where are the names stored? Are they stored in "yourtable"? If so, include the name field in the SELECT query. If the names are in a different table, then you should have a FK (Foreign Key) in the "yourtable" so that you can JOIN the records in the "yourtable" to the records in the related table with the names.

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.