title: PDO Prepare 2 tables in one query
body: <p>I made a database with 2 tables (students, teachers).
  Each one has 1 row. So I have a student and a teacher. Both of them have id=1 because inside each table I have a column called id which is Auto Increment.</p>
  
  <p>I did a login page and I used these:</p>
  
  <pre><code>$sth_username = $dbh-&gt;prepare("SELECT name, id FROM students WHERE name = :name UNION SELECT name, id FROM teachers WHERE name = :name");
  $sth_username-&gt;bindParam(":name", $name);
  $sth_password = $dbh-&gt;prepare("SELECT password, salt FROM students WHERE name = :name UNION SELECT password, salt FROM teachers WHERE name = :name");
  $sth_password-&gt;bindParam(":name", $name);
  </code></pre>
  
  <p>I am able to login and the redirect to index.php. Inside index.php I have this</p>
  
  <pre><code>if (isset($_SESSION['id'])) {
      $sth = $dbh-&gt;prepare("SELECT * FROM students WHERE id = :id");
      $sth-&gt;bindParam(":id", $_SESSION['id']);
      $sth-&gt;execute();
      $result = $sth-&gt;fetch(PDO::FETCH_ASSOC);
      print "Name: ".$result['name']."&lt;br&gt;";
      print "Nickname: ".$result['nickname']."&lt;br&gt;";
      print "Town: ".$result['town']."&lt;br&gt;";
      print "Adress: ".$result['adress']."&lt;br&gt;";
      print "E-Mail: ".$result['email']."&lt;br&gt;";
  </code></pre>
  
  <p>If I loggin as a student it shows me these informations Name Nickname etc ... 
  I want to loggin as a teacher and see those stats from the teacher's row. (Teacher's) Name, (Teacher's) Nickname etc ... I don't know what to write inside <code>$sth = $dbh-&gt;prepare("SELECT * FROM students WHERE id = :id");</code>to make that working. I tried UNION and INNER JOIN but it didn'w work properly. I'm sure it is a simple thing and I will be very happy if you will help me.</p>
  
  <p>Thank you and sorry for my english.</p>