title: MySQL - UNION ALL with queries on same table
body: <p>I would like to use some query that i found on <a href="https://stackoverflow.com/questions/6102824/is-there-a-postgres-closest-operator/">this</a> site - I adapted it for my own purposes:</p>
  
  <pre><code>SELECT * FROM 
  (
  (
  SELECT id, lng FROM stations WHERE lng &gt;= 18.123 ORDER BY lng LIMIT 1
  ) AS result1
  UNION ALL
  (
  SELECT id, lng FROM stations WHERE lng &lt; 18.123 ORDER BY lng LIMIT 1
  ) AS result2
  )
  ORDER BY abs(18.123-lng) LIMIT 1;
  </code></pre>
  
  <p>But I got an error <code>Syntax error, unexpected AS, expecting UNION_SYM or ')'</code> </p>
  
  <p>When i try to do it without aliases, I (obviously) keep getting  error <code>Error Code: 1248. Every derived table must have its own alias</code></p>
  
  <p>Could you please help me figure out what am I doing wrong? Thank you in advance.</p>