Solved

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

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

Accepted Solution

by:
Dan Craciun earned 500 total points
Comment Utility
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
Comment Utility
Thanks a lot
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
Glad I could help!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now