Solved

Exports Multiple MySQL Tables To CSV File

Posted on 2011-03-22
2
561 Views
Last Modified: 2012-05-11
I've found these queries...

http://www.electrictoolbox.com/mysql-export-data-csv/

http://ariejan.net/2008/11/27/export-csv-directly-from-mysql/

So I'm trying to use left join etc to build a query to export multiple tables.

What I need to state every column from every table with the SELECT rather than using select all * ?

Just I'm having some issues getting it working and want to clear some things up so I'm not on an impossible path.

Thanks for your help
0
Comment
Question by:Ryan Bayne
2 Comments
 
LVL 5

Accepted Solution

by:
tygrus2 earned 125 total points
ID: 35196276
If you join tables then the common index fields will be repeated & renamed for each occurance. Use the tablename.fieldname references to explicitly list the fields to SELECT.

eg.
SELECT Order.OrderID, OrderLine.ProductID, OrderLine.Qty
INTO OUTFILE '/tmp/orderitems.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM Order LEFT JOIN OrderLine ON Order.OrderID=OrderLine.OrderID

Open in new window

Example is a bad choice for LEFT join but you get the idea.
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 35197574
Yes so they would that had not entered my mind yet. This is for a Wordpress plugin. So I need to provide the user with a way to select the tables they want to export plus select the columns.

The problem I'm having must be syntax then because I've tried something like what your suggesting. At least I know I was on the right path that is all I wanted really, will just dump and execute some queries in the MySQL gui.

I must remember to check the users input for any duplicate index selections.

Thanks for clearing this up
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question