Solved

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

Posted on 2014-03-24
3
487 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

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…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

738 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