title: Select from another column if selected value is '0' in mySQL
body: <p>I have a table similar to the table below</p>
  
  <pre><code>id | mainID | subID
  1  |   11    |   0
  2  |   12    |   0 
  3  |   13    |   20
  4  |   13    |   21
  5  |   15    |   0
  </code></pre>
  
  <p>I need to select all the " mainID " if the subID is 0. If subID is not 0 then select subID instead of mainIdD</p>
  
  <p>Resulting table</p>
  
  <pre><code>id | resultId
  1  | 11
  2  | 12
  3  | 20
  4  | 21
  5  | 15
  </code></pre>
  
  <p>The subID column value is not null so I can't use ifnull here. Can this be done by just using a sql query? And not use write function for it in php. I know it can be done in php but i need this data from the sql query itself.</p>