title: MySQL CSV Export with Data and Header
body: <p>I have tried to export CSV from the MySQL Database with the Header too. But I am getting the following error-</p>
  
  <pre><code>ERROR 1222 (21000): The used SELECT statements have a different number of columns
  </code></pre>
  
  <p>The MySQL Query is as below-</p>
  
  <pre><code>SELECT * FROM (
    (SELECT COLUMN_NAME
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'ORDERS'
      AND TABLE_SCHEMA = 'REMOTE'
      ORDER BY ORDINAL_POSITION)
    UNION ALL
    (SELECT * FROM ORDERS WHERE orderDate&gt;='2018-05-07')) AS TBL
  INTO OUTFILE 'C:/xampp/htdocs/WES/DBScript/SS_Orders.csv'
  FIELDS TERMINATED BY ','
  ENCLOSED BY '"'
  LINES TERMINATED BY '\n';
  </code></pre>