title: Select 2 tables in one php select statement
body: <p>I have two tables in mysql</p>
  
  <p><code>practice_sheets</code> and <code>parent_pin</code></p>
  
  <p>And I want to use one select statement and get data from both tables. </p>
  
  <p>I have tried</p>
  
  <pre><code>$result = mysqli_query($con,"SELECT * FROM practice_sheets AND parent_pin 
  WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
  </code></pre>
  
  <p>and also: </p>
  
  <pre><code>$result = mysqli_query($con,"SELECT * FROM practice_sheets, parent_pin 
  WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
  </code></pre>
  
  <p>I've never tried to do this before and the previous solutions are what I found searching.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I think it would help if I included my full code. the table data is going into a table on my page. the <code>student_name</code> field from the practice_sheets and <code>parents_student</code> from parent_pin will be matched.</p>
  
  <pre><code>&lt;?php
  $con=mysqli_connect();
  // Check connection
  
  if (mysqli_connect_errno()){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $result = mysqli_query($con,"SELECT * FROM practice_sheets
                                                      WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
  $numrows = mysqli_num_rows($result);
  
  if($numrows == 0)                    {
      echo "&lt;div class='alert alert-danger'&gt;";
      echo "No Entries, See your instructor for details.";
      echo "&lt;/div&gt;";
  } else                    {
      echo "&lt;table class='mws-table table-striped table-hover'&gt;";
      echo "&lt;thead align='center'&gt;";
      echo "&lt;tr&gt;";
      echo "&lt;th&gt;Sheet Number&lt;/th&gt;";
      echo "&lt;th&gt;Total Minutes&lt;/th&gt;";
      echo "&lt;th&gt;Due Date&lt;/th&gt;";
      echo "&lt;th&gt;PIN&lt;/th&gt;";
      echo "&lt;th&gt;View&lt;/th&gt;";
      echo "&lt;/tr&gt;";
      echo "&lt;/thead&gt;";
      echo "&lt;tbody align='center'&gt;";
      while($row = mysqli_fetch_array($result)){
  
          if ($row["total_min"]&gt;=$row["required_min"]) {
              echo "&lt;tr class='success'&gt;";
              echo "&lt;td&gt;" . $row['id'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['total_min'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['due_date'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['parent_pin'] . "&lt;/td&gt;";
              echo "&lt;td&gt; &lt;a href='account/practiceSheets?id=" . $row["id"] . "&amp;total_min=" . $row["total_min"] ."&amp;due_date=" . $row["due_date"] ."&amp;mon_min=" . $row["mon_min"] ."&amp;tues_min=" . $row["tues_min"] ."&amp;wed_min=" . $row["wed_min"] ."&amp;thurs_min=" . $row["thurs_min"] ."&amp;fri_min=" . $row["fri_min"] ."&amp;sat_min=" . $row["sat_min"] ."&amp;sun_min=" . $row["sun_min"] ."&amp;name=" . $row["student_name"] ."&amp;assignment=" . $row["assignment"] ."&amp;required_min=" . $row["required_min"] ."'&gt; &lt;i class='icon-eye-open'&gt; &lt;/i&gt; &lt;/a&gt; &lt;/td&gt;";
              echo "&lt;/tr&gt;";
          } else {
              echo "&lt;tr class='info'&gt;";
              echo "&lt;td&gt;" . $row['id'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['total_min'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['due_date'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['parent_pin'] . "&lt;/td&gt;";
              echo "&lt;td&gt; &lt;a href='account/practiceSheets?id=" . $row["id"] . "&amp;total_min=" . $row["total_min"] ."&amp;due_date=" . $row["due_date"] ."&amp;mon_min=" . $row["mon_min"] ."&amp;tues_min=" . $row["tues_min"] ."&amp;wed_min=" . $row["wed_min"] ."&amp;thurs_min=" . $row["thurs_min"] ."&amp;fri_min=" . $row["fri_min"] ."&amp;sat_min=" . $row["sat_min"] ."&amp;sun_min=" . $row["sun_min"] ."&amp;name=" . $row["student_name"] ."&amp;assignment=" . $row["assignment"] ."&amp;required_min=" . $row["required_min"] ."'&gt; &lt;i class='icon-eye-open'&gt; &lt;/i&gt; &lt;/a&gt; &lt;/td&gt;";
              echo "&lt;/tr&gt;";
          }
  
      }
  
      echo "&lt;/tbody&gt;";
      echo "&lt;/table&gt;";
      mysqli_close($con);
  }
  
  ?&gt;
  </code></pre>