2012-03-19 54 views
0

我需要根据自定义元数据导出一些帖子。我无法导出帖子的ID,因为我将数据导入到其他数据库时会遇到重复密钥问题。在SQL查询中重复列标题?

当我运行SQL查询来选择哪些领域,我不包括ID:

SELECT 'post_author', 
     'post_date', 
     'post_content', 
     'post_title', 
     'post_excerpt', 
     'post_status', 
     'comment_status', 
     'ping_status', 
     'post_password', 
     'post_name', 
     'post_modified', 
     'post_content_filtered', 
     'post_parent', 
     'guid', 
     'post_type', 
     'post_mime_type', 
     'comment_count' 
FROM wp_posts 
     INNER JOIN wp_postmeta 
     ON wp_postmeta.post_ID = wp_posts.ID 
WHERE (wp_postmeta.meta_key = 'InternalOnly' 
     AND wp_postmeta.meta_value IS NOT NULL); 

我得到的列标题列中的每个条目:http://screencast.com/t/A8ySD6frl6Z

所以基本上我需要在运行查询时引用帖子的ID,但不能在输出中包含ID。难道我做错了什么?

+0

为什么您使用单引号?把你的column_titles放在' – 2012-03-19 21:29:32

+0

之间哈哈,好吧,我收到消息 – AlxVallejo 2012-03-19 23:28:07

回答

4

您选择字符串文字,而不是场。拿出单引号,你应该是好的(假设查询是正确的)

SELECT post_author, post_date, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, post_modified, post_content_filtered, post_parent, guid, post_type, post_mime_type, comment_count FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID WHERE (wp_postmeta.meta_key = 'InternalOnly' AND wp_postmeta.meta_value IS NOT NULL); 
2

您需要删除报价:SELECT post_author, ...

1

问题是你引用每个列名。你在这种情况下要求它做的是选择文本字符串“post_author”,“post_date”等,而不是要求它从这些列中选择数据。将其更正为“SELECT post_author,post_date ...”