Wednesday, 23 May 2012

How to fetch data in excel/csv format using mysql query?

Dear All,

Suppose you have a query given below:
SELECT ud.email FROM user_detail ud group by ud.email having count(ud.email) > 1;

The above query return all email addresses which are duplicate in the system.

Now go to server and type following:

## Fetching duplicate email address and saving them into file...   
mysql -uuser_name -p -hhost_name -A -Ddatabase_name -B --skip-column-names -e "SELECT ud.user_id, ud.email FROM user_detail ud group by ud.email having count(ud.email) > 1;">  /var/www/duplicateEmail

"/var/www/" is a path where you want to save file.
"duplicateEmail" is a file name.


Cheers!

1 comment:

  1. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!
    PHP Mysql Developers in India

    ReplyDelete