title: How to select the id with max value that in another table
body: <p>Here are 2 tables.</p>
  
  <pre><code>Table 1
  id  value
  1   3
  2   2
  3   3
  4   1
  5   4
  6   3
  </code></pre>
  
  <pre><code>Table 2
  id
  1
  3
  4
  </code></pre>
  
  <p>How do I get the ids that are in Table 2 which have the max value in Table 1?</p>
  
  <p>Output:</p>
  
  <pre><code>id
  1
  3
  </code></pre>
  
  <p>I already tried the following to get the max value, but I cannot figure out how to use it in a single query to get the matching rows. Because I think I need to select from the same table I just inner joined.</p>
  
  <pre><code>select max(table1.value) 
  from table2 
  inner join table1 on table1.id = table2.id;
  </code></pre>