如何复制JOIN-ed sql表?

时间:2013-06-03 13:19:44

标签: php sql wordpress

我试过了:

INSERT INTO wp_posts_copy * (SELECT 
        *
FROM 
        wp_posts
        JOIN wp_term_relationships
                ON wp_posts.ID = wp_term_relationships.object_id
WHERE 
   wp_term_relationships.term_taxonomy_id = "48")

SQL数据库:

wp_posts => 
ID
post_author
post_date
post_date_gmt
post_content
post_title
post_excerpt
post_status
comment_status
ping_status
post_password
post_name
to_ping
pinged
post_modified
post_modified_gmt
post_content_filtered
post_parent
guid
menu_order
post_type 
post_mime_type
comment_count

wp_term_relationships =>
object_id
term_taxonomy_id
term_order

我想复制或导出那个类别中的id为48的wp_posts。选择正常,但我不知道如何复制它们。那么,我该如何复制所选数据呢?它来自WP数据库。

1 个答案:

答案 0 :(得分:2)

要仅复制wp_posts中的列,您必须使用wp_posts.*代替*或命名您要使用的所有列

INSERT INTO wp_posts_copy
SELECT wp_posts.* FROM wp_posts
JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
WHERE wp_term_relationships.term_taxonomy_id = "48"