searls03 Posted February 29, 2016 Share Posted February 29, 2016 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 29, 2016 Share Posted February 29, 2016 You need to use find records where col1 or col2 is equal to the least number WHERE (SELECT LEAST(MIN(COL1),MIN(COL2))FROM yourtable) IN (COL1, COL2) Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 29, 2016 Share Posted February 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.