title: How to write a SQL statement which gets results via a relationship table? (many to many)
body: <p>I have 3 tables (archive has many sections, section (may) belong to many archives):</p>
  
  <ul>
  <li><p><code>archive</code></p>
  
  <ul>
  <li><code>id PK</code></li>
  <li><code>description</code></li>
  </ul></li>
  <li><p><code>archive_to_section</code></p>
  
  <ul>
  <li><code>archive_id PK FK</code></li>
  <li><code>section_id PK FK</code></li>
  </ul></li>
  <li><p><code>section</code></p>
  
  <ul>
  <li><code>id PK</code></li>
  <li><code>description</code></li>
  </ul></li>
  </ul>
  
  <p>What would the SQL look like to list all the sections that belong a certain archive id?</p>
  
  <p>I am just learning SQL. From what I've read it sounds like I would need a join, or union? FYI I'm using postgres.</p>
  
  <hr>
  
  <p><strong>[Edit]</strong> This is the answer from gdean2323 written without aliases:</p>
  
  <pre><code>SELECT section.* 
  FROM section 
  INNER JOIN archive_to_section 
  ON section.id = archive_to_section.section_id 
  WHERE archive_to_section.archive_id = $this_archive_id
  </code></pre>