Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-24
3
Medium Priority
?
501 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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

916 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