title: Comparing values of columns from 3 tables - MySQL
body: <p>following question:</p>
  
  <p>I'm working with 3 tables = actors, movies, roles. I'm trying to find all the movies a given actor, say 'Robin Williams' has been in by comparing the specific actor id since there be may more than one actor with the same name. The actors table has the following relevant columns: first_name, last_name, id - the movies table has columns: id (the movie's id) - and the roles table has: actor_id and movie_id. </p>
  
  <p>Do I JOIN the tables or use UNION? How do I compare columns from different tables when the columns have different names?</p>
  
  <p>Thank you!</p>
  
  <p>Just for reference:</p>
  
  <p>Table actors:</p>
  
  <pre><code>mysql&gt; SELECT *
      -&gt; FROM actors;
  +--------+--------------------+------------------------+--------+------------+
  | id     | first_name         | last_name              | gender | film_count |
  +--------+--------------------+------------------------+--------+------------+
  |    933 | Lewis              | Abernathy              | M      |          1 |
  |   2547 | Andrew             | Adamson                | M      |          1 |
  |   2700 | William            | Addy                   | M      |          1 |
  </code></pre>
  
  <p>Table movies:</p>
  
  <pre><code>mysql&gt; SELECT *
      -&gt; FROM movies;
  +--------+------------------------------+------+------+
  | id     | name                         | year | rank |
  +--------+------------------------------+------+------+
  |  10920 | Aliens                       | 1986 |  8.2 |
  |  17173 | Animal House                 | 1978 |  7.5 |
  |  18979 | Apollo 13                    | 1995 |  7.5 |
  </code></pre>
  
  <p>Table roles:</p>
  
  <pre><code>mysql&gt; SELECT *
      -&gt; FROM roles;
  +----------+----------+-------------------------------+
  | actor_id | movie_id | role                          |
  +----------+----------+-------------------------------+
  |    16844 |    10920 | Lydecker                      |
  |    36641 |    10920 | Russ Jorden                   |
  |    42278 |    10920 | Cpl. Dwayne Hicks             |
  </code></pre>
  
  <p>At first I tried setting each check equal to a PHP variable and comparing them but that seemed wrong, then I tried:</p>
  
  <pre><code>mysql&gt; SELECT roles.actor_id, roles.movie_id, movies.id, actors.id
      -&gt; FROM roles
      -&gt; JOIN movies, actors
      -&gt; ON roles.actor_id = actors.id &amp;&amp; roles.movie_id =movies.id;
  </code></pre>
  
  <p>which again does not work.</p>