SQL query results into CSV file

You must have fired those select statements tons of times. So you hit a query, get your results and you are done. But what if the next day you felt like going through the results you found the other day. Simple..hit the query again. But what if the query was complex and you need the results fast. What you shud have done in the first place was to generate a CSV file out of your query result.

The way I do it and others must be doing is pretty simple.

So say your query was something like this:

mysql> select * from users where dob > ‘1981-10-07’;

To get the output of this query into a CSV file is pretty simple. Do dis….

mysql> select * from users where dob > ‘1981-10-07’

Bingo..u have ur file waiting for u. In case u don’t know where that file got created…check in dis location:


So its dat very simple. So next time just keep this in mind.

And though this is off topic, here is a way to add time to a datetime attribute in your table.

mysql> select batchid, date_add(created_at, interval ‘9:30’ HOUR_MINUTE)
from batches where created_at >= ‘2000-01-01 00:00:00’ and created_at <= ‘2000-01-02 01:00:00’ ;

Simple enough. 🙂


5 thoughts on “SQL query results into CSV file

  1. I cover my freshly sharpened hook with paste and coat the
    hair and bait in paste. The 360 Series from Aqua-Vu is specifically designed
    with a rugged encasement for ice fishing. One can find another 2
    options as to wholesale fishing rod, which might be hollow-tip rods and reels and
    spliced-tip rods.

  2. 00 for the fondant covered frosting, chocolate ganache icing, and marzipan frosting and $.
    For instance, it is an excellent idea to prepare the birthday cake of
    a golf lover in the shape of a golf ball in a golf course.
    Frost the cupcakes in different colors using frosting and food coloring.

  3. s better to use whole foods made from scratch for good health.
    For many working to lose weight, one failure is enough to get them off the path to success.
    Now, the average healthy amount people are supposed to lose is 2 pounds per week.

  4. s better to use whole foods made from scratch for good health.

    Authorities inside the area will need to have an intensive understanding of laboratory and
    labeling techniques, infection security precautions, appropriate blood attract approaches to the elderly and for infants and even more.
    When you’re about to start on your weight loss plan, it’s a good idea to think
    about your end goal and chunk it down into smaller goals.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s