title: How to sort data in mysql UNION subquery?
body: <p>i need to select all vip from table and order them by rand, and then to add other data sorted by date. In first subquery everything is ok, but in second <strong>order by spa_date DESC</strong> does not work. I know that ORDER BY clauses inside UNION subqueries are ignored without a LIMIT(but order by rand() works), but i need limit from all query (1+2),  not from subquery</p>
  
  <pre><code>SELECT * FROM
          (
             select *,DATE_FORMAT(spa_date,"%e %M %Y") as spa_date_out 
              from spa join city using (city_id) 
  
              where spa_vip=1
              order by RAND() 
           )   as A
          UNION
          (
             select *,DATE_FORMAT(spa_date,"%e %M %Y") as spa_date_out 
              from spa join city using (city_id) 
  
              where spa_vip=0
              order by spa_date DESC )
  
          limit 10,10
  </code></pre>
  
  <p>the question:<br>
  i need to select all spa_id where spa_vip=1 and order it by RAND(), then i need to select all spa_id where spa_vip=0 and order it by spa_date, union this 2 subqueries and select data with limit 0,10 and so on for page view</p>