Jump to content

Filtering SQL results


unknown101

Recommended Posts

Hi Guys, I have the following query:

 

$highest_avg=mysql_query("SELECT * FROM track_tbl where Artist_ID='$get_artist_ID'") or die ('Error: '.mysql_error ());

$theresult = mysql_query($highest_avg);					
	while ($row = mysql_fetch_array($highest_avg))				
	{
                          //Pull any any details needed		
	$gettherating = $row['Average_rating'];
                          }

 

This query returns the artist_id, all their tracks and Track_IDS plus the current average rating for each (in the field Rating).  Now from the result I want to be able to select the highest rated from each artist and output this (so essentially only returning a single track from each seperate artist).  So for example I have a table like:

 

Artist ID  || Track_ID  ||  Rating

1                  1                4

1                  2                6

 

Obivouly both are from the same artist, but they have 2 different tracks.. I want to select the highest rated in this case Track 2.

 

I have tried to use the MAX function in my sql query but it doesnt seem to be working:|  It just returns the first record. Im guessing I could add to the query above and do it all in one, but im still learning php/sql so having a few problems.  Could anyone give me some pointers or advice,

 

Thanks in advance

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.