Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
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 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…

749 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