MySQL IF statement?

Discussion in 'MySQL' started by mattgoody, Feb 22, 2008.

  1. #1
    I have 2 tables, one containing the names of basketball players called "players", and another containing their stats for a single day called "stats". Some players in the "players" table do not appear in the "stats" table because they did not play that night. I want to be able to do a:
    SELECT * FROM players JOIN stats ON players.last = stats.last AND players.first = stats.first;
    Code (markup):
    So that even if the players do not appear in "stats" table, they will be selected, just all their stats will be NULL or something. Is there anyway to do this? So pretty much it would be:
    IF players.last = stats.last AND players.first = stats.first 
    THEN SELECT * FROM players JOIN stats ON players.last = stats.last AND players.first = stats.first 
    ELSE SELECT * FOM players
    END IF
    Code (markup):
    Is there any way to do this?

    Thanks
    -Matt
     
    mattgoody, Feb 22, 2008 IP
  2. mattgoody

    mattgoody Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nvm, im stupid, i just had to do an outer join.
     
    mattgoody, Feb 22, 2008 IP