Exports Multiple MySQL Tables To CSV File

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

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
Question by:Ryan Bayne
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

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.

SELECT Order.OrderID, OrderLine.ProductID, OrderLine.Qty
INTO OUTFILE '/tmp/orderitems.csv'
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.

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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…

623 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