sqlsemi-join

What kind of join do I need?


I have a votes table:

 votes
-----------------
 userid   gameid
-------  --------
   a        1
   a        2
   a        3
   b        1
   b        2

and a games table:

 games
----------------
 gameid   title
 ------   ------
    1       foo
    2       bar
    3       fizz
    4       buzz

What kind of a join would I use to perform the query "Select * from games where [user A voted on the game]"?

I've tried following Jeff's guide, but I'm not getting the expected results.


Solution

  • You would use an INNER join to establish the relationship between the common gameid field;

    select
      votes.userid,
      games.title
    from games
      inner join votes on (votes.gameid = game.gameid)
    where
      votes.userid = 'a'