0

having a little trouble, how could I alter this mysql query so that if there are rows in the member_results table it will run the query below but if there is none then pretty much run the query below just without the SUMS() and the joins with the member_results table. I am guessing it can be done with the IF statement in mysql I just have no clue really how to implement with the query below.

Any help is much appreciated.

$result = mysql_query(" SELECT m.member_id, m.teamname, 
  Sum(Case When r.track_id = '$chosentrack' -1 AND r.track_id >= l.start_race 
  Then total_points Else 0 End) LastRacePoints,
  Sum(Case When r.track_id <= '$chosentrack' -1 AND r.track_id >= l.start_race
  Then total_points Else 0 End) TotalPoints 
FROM members m
  Join members_leagues l
  On l.member_id = m.member_id  
  Join member_results r
  On r.member_id = m.member_id
Where l.league_id = '$chosenleague'
  Group By m.member_id
  Order By TotalPoints Desc, LastRacePoints DESC, m.teamname Desc ") 
or die ("Error - could not display league");
0

1 Answer 1

3

Just replace Join member_results r with Left Join member_results r and it should work. You should get NULLs for the sums if there are no results.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.