- I've got a 30K row table
- When I run a long, 50-line query on that table, a GROUP function reduces the number of rows to 7K
- I want to export the grouped 7K rows as a new table, or save them as a CSV
When I attempt to export, instead of getting the grouped 7K rows, I get the old, pre-query 30K rows. What am I doing wrong, and what should I be doing?
NOTE: I'm not a coder, so I'd really appreciate a solution that just used the phpMyAdmin GUI.
Execute your sql query in the SQL tab of phpMyAdmin.
After execution, scroll down the page and look for “Query results operations”
Click “Export” link from the above and you will get the page to export all the results of the queries to desired format.
Instead of the export button at the top of the GUI, use the one at the bottom, within the "Query results operations" box. That is the one you want.
On some query it's not possible in a direct way.
You must write the query result to a table through the
create table as
syntax And then you can follow the normal export instructions: https://serverfault.com/a/300342/256884You've already got the query? You can insert into a new table using another query's results
Looks like the steps you need:
INSERT INTO newTable (field1, field2, field3) SELECT field1, field2, field3 FROM otherTable GROUP BY field1
Adjust for your 50-line query.
I still needed an answer to this old question for a query from multiple tables and I came up with a good one. As others have stated, you can try the Export option under "Query results operations". As another other people noted, that does not always work and it may just give you all the rows from one table. That option did not work in my case. I also wanted something simpler than writing code to insert the results into a new table and then exporting that.
I found two easy ways to do this.
Method 1: Copy and paste
Check the "Show all" box above the results, highlight all the results, copy, and paste into a spreadsheet. That worked for me in Excel. However, the results preview truncates cell values that are too long. Therefore, this may not work for you if your cell values are long and you need the complete values.
Method 2: Create view
Under "Query results operations", there is an option to "Create view". Created views will appear below the database Tables in a new "Views" category. Views are basically persistent tables that show custom query results. Click "Create view", enter a name for the view and Go. Now you successfully use the Export option under "Query results operations" while in the View.