We have a WordPress site that contains a Q&A plugin, that needs to be moved to a different hosting. The Q&A posts only make up for a fraction of the total Posts table, so I want to filter them out using a SQL query.
I want to select everything in the DB, through PhpMyAdmin, for the rows that match one of the following criteria:
post_type = "answer"
post_type = "question"
- post_type contains revision, preceded by the ID of either one of the previous criteria. For example:
21-revision-v1
or10903-revision-v1
Where I want to select those posts of which the first numerical part matches the ID of posts selected in the previous 2 requirements.
I am a complete novice to SQL so I started with some googling, and found the concept of Temporary Tables. Which lead me to create this bit of code:
SELECT * INTO #QA
FROM `wp_posts` WHERE
`post_type` = "answer" OR
`post_type` = "question"
However I get the following error:
#1064 – Er is iets fout in de gebruikte syntax bij ‘FROM
wp_posts
WHERE
post_type
= "answer" OR
post_type
= "question" LIMI’ in regel 2
Which translates to "There is somthing wrong with the syntax near"….
Is what I am attempting even feasible?
3
Answers
MySQL does not support the
select ... into ...
syntax to write to a table, as pinpointed in the documentation.Instead you can use
insert ... select
:The
SELECT * INTO...
syntax is used to create a new table.If this is what you want then the syntax for MySql is:
The syntax that you are using is most commonly associated with SQL Server. MySQL uses the (more common)
create table as
syntax. And, it allows specifically for temporary tables in the syntax.So, the equivalent in MySQL is
CREATE TABLE AS
:Note that a temporary tables is a very specific type of table that exists only in the current "session" — say, your current connection to the database. It is not visible to other users and it will disappear when you reconnect to the database.