title: SELECT where with multiple conditions in ONE query
body: <p>There are <strong>two</strong> things I want to achieve.</p>
  
  <p>This is my database table called "table".</p>
  
  <pre><code>id | friend
  ---|--------
  1  | null
  2  | 1
  3  | 0
  4  | 3
  5  | 3
  6  | null
  </code></pre>
  
  <p>There are two SELECT queries I want to do.</p>
  
  <pre><code>$id = 3;
  SELECT * FROM table WHERE id = $id; // Not sql injection safe, just an example
  </code></pre>
  
  <p>This should select row id = 3. If that row's <code>friend</code> column = 0, then: </p>
  
  <pre><code>SELECT rows WHERE friend = $id.
  </code></pre>
  
  <p>If that row's <code>friend</code> column is something other than 0, then just return that row, row 3. <strong>But</strong> since my table above shows that row id 3's <code>friend</code> column = 0, this should altogether return rows: 3, 4, 5.</p>
  
  <hr>
  
  <p><strong>Also, another scenario a something a little different:</strong></p>
  
  <pre><code>$id = 5;
  SELECT * FROM table WHERE id = $id;
  </code></pre>
  
  <p>If that row's <code>friend</code> column &lt;> (does NOT equal) 0 AND IS NOT NULL, then use the <code>friend</code> number and:</p>
  
  <pre><code>SELECT * WHERE id = friend from previous table.
  </code></pre>
  
  <p>In this example, it will return rows 3, 4, 5 because ID = 5 and the <code>friend</code> ID of 5 is 3. So we search columns <code>id</code> AND <code>friend</code> for 3 and we select it.</p>
  
  <p>I want to combine all of those together into one MySQL SELECT query. How can I do that?</p>
  
  <p>Any help will be appreciated!</p>