title: MySQL: Export all rows with the same column data into same file
body: <p>Say you have a large table with thousands of rows and 3 columns, looking something like this: </p>
  
  <pre><code>Name               City               Birthyear
  
  Egon Spengler       New York           1957  
  Mac Taylor          New York           1955  
  Sarah Connor        Los Angeles        1959  
  Jean-Luc Picard     La Barre           2305  
  Ellen Ripley        Nostromo           2092  
  James T. Kirk       Riverside          2233  
  Henry Jones         Chicago            1899  
  Jason Bourne        Paris              1971</code></pre>
  
  <p>......
  and so on. Is it possible to sort people by City into separate files?
  For example, if you have 100 or more cities in the table, is there a query that would create 100 or more files with people names and birth years in it? For a smaller number of cities one could use </p>
  
  <p>-e "select Name, Birthyear from Table where City = New York" > NewYork.csv</p>
  
  <p>and so on for each city in the table.
  But it's not fun to do it manually if you have hundreds of cities.</p>