title: Joining and querying two tables with conflicting column names
body: <p>Imagine I have two tables: <strong>users</strong> and <strong>students</strong></p>
  
  <p>Each table has an id and email column. I want to be able to search for emails from both tables. I can join the two tables where the IDs match like this:</p>
  
  <pre><code>SELECT users.email,students.email as student_email FROM users
  INNER JOIN students ON users.id = students.id
  </code></pre>
  
  <p>I can't search the email column because they have the same column name (email). So if I try use <code>WHERE</code> it complains that the column (email) is ambiguous. If I try use <strong>student_email</strong> it complains that the column doesn't exist.</p>
  
  <p>If the two tables didn't use an identical column name (email) then it would be fine when I use <code>WHERE</code>.</p>
  
  <p>The only solution I can think of is to get all rows and then loop around them and search the email strings manually. This is extremely slow compared to using MySQL like this:</p>
  
  <pre><code>SELECT users.email,students.email as student_email FROM users
  INNER JOIN students ON users.id = students.id
  WHERE email LIKE '%test@email.com%' OR student_email LIKE '%test@email.com%'
  </code></pre>
  
  <p>But of course this doesn't work because <code>WHERE</code> looks for the original column names before the <code>SELECT</code>. </p>
  
  <p>How can I get around this without getting all the rows and the looping it? Maybe it is a union, rather than a <code>JOIN</code>? I'm not sure...</p>