Solved

How to do an Insert into Select with inner joins (on wordpress db) in different database

Posted on 2014-03-24
3
491 Views
Last Modified: 2014-03-25
Hello

I need to manually copy from data from one wordpress site from another.
This is the query to retrieve my data

SELECT *
FROM wp_posts AS p
INNER JOIN wp_term_relationships tr ON p.id = tr.object_id
INNER JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN wp_terms t ON t.term_id = tt.term_id
WHERE tt.Taxonomy =  "Category" AND t.Name = 'Some Category"

I was wondering if there was an easy way to turn this into an INSERT into SELECT statement for a different database. The tables will naturally be exactly the same in the other database as its a wordpress database. The other database is on the same server.

Please do not recommend a plugin :)

Thanks very much in advance
0
Comment
Question by:andieje
[X]
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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39951177
I don't think you can do it in one go, but you can do a SELECT INTO OUTFILE to save your query's results into a file and then LOAD DATA INFILE in the other db.

SELECT * 
FROM wp_posts AS p
INNER JOIN wp_term_relationships tr ON p.id = tr.object_id
INNER JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN wp_terms t ON t.term_id = tt.term_id
WHERE tt.Taxonomy =  "Category" AND t.Name = 'Some Category"
INTO OUTFILE "out.sql"

Open in new window


HTH,
Dan
0
 

Author Closing Comment

by:andieje
ID: 39954413
Thanks a lot
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39954417
Glad I could help!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
This video teaches users how to migrate an existing Wordpress website to a new domain.

615 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