unknown101 Posted April 16, 2008 Share Posted April 16, 2008 I have the following query: highest_avg=mysql_query("SELECT * FROM track_tbl where Artist_ID='$get_artist_ID'") This returns the following details: Track_ID || Track || Album_ID || Artist_ID || Average_rating || 2 Blah 4 5 9 2 Blah1 4 5 6 Now both tracks are the same artist, but I want to select the one with the hightest rating - so in this case track "Blah". Also keeping in mind that I cant order in Descending order and limit to 1 because the artist may have many tracks with the same ratings. If multiple tracks have the same rating then i want to use a random function to select 1 record. Can anyone suggest how to do this? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/101342-selecting-the-max-value/ Share on other sites More sharing options...
AdamCox9 Posted April 16, 2008 Share Posted April 16, 2008 <?php // Make a MySQL Connection $query = "SELECT type, MAX(price) FROM products GROUP BY type"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "The most expensive ". $row['type']. " is $" .$row['MAX(price)']; echo "<br />"; } ?> Here is a sample. This is found at: http://www.tizag.com/mysqlTutorial/mysqlmax.php Link to comment https://forums.phpfreaks.com/topic/101342-selecting-the-max-value/#findComment-518347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.