title: Double select from a same table
body: <p>I have a table categories that looks like this. My categories can span up to 4 levels deep but I have chosen to always show only one level bellow the selected one.</p>
  
  <pre><code>| id | parent_id | name | ... |
  | 1  |    0      |  A   | ... |
  | 2  |    1      |  A1  | ... |
  | 3  |    2      |  A2  | ... |
  | 4  |    1      |  A3  | ... |
  | 5  |    0      |  B   | ... |
  </code></pre>
  
  <p>Basically I'm trying to select parent categories and their first level children. So after select I should get all rows where <code>parent_id = 0</code> and where <code>parent_id = parent_id</code> from the parents.</p>
  
  <p>I should get:</p>
  
  <pre><code>| id | parent_id | name | ... |
  | 1  |     0     |  A   | ... |
  | 2  |     1     |  A1  | ... |
  | 4  |     1     |  A2  | ... |
  | 5  |     0     |  B   | ... |
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>SELECT * AS t1 FROM categories
      WHERE parent_id = 0 AND WHERE parent_id = t1.id;
  </code></pre>
  
  <p>I'm very new to SQL with code I could do this easy with PHP but I don't want to select everything and then do a complex sort function.  </p>
  
  <p>How can I select the table once to select <code>parent_id</code> and then do a second select into this select I just did where parent_id's from categories table equal id's in the select I just did.</p>