Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 子查询使用Wordpress postmeta查询返回多行_Mysql_Sql_Wordpress_Post Meta - Fatal编程技术网

Mysql 子查询使用Wordpress postmeta查询返回多行

Mysql 子查询使用Wordpress postmeta查询返回多行,mysql,sql,wordpress,post-meta,Mysql,Sql,Wordpress,Post Meta,我试图从子网站的POST和POSTETA表中提取数据: SELECT xyz_8_posts.ID, (select xyz_8_postmeta.meta_value from xyz_8_postmeta inner join xyz_8_posts on xyz_8_postmeta.post_id = xyz_8_posts.ID where xyz_8_postmeta.meta_key = 'presentation_title' AND xyz_8_postmeta.post_i

我试图从子网站的POST和POSTETA表中提取数据:

SELECT xyz_8_posts.ID,

(select xyz_8_postmeta.meta_value
from xyz_8_postmeta
inner join xyz_8_posts
on xyz_8_postmeta.post_id = xyz_8_posts.ID
where xyz_8_postmeta.meta_key = 'presentation_title'
AND xyz_8_postmeta.post_id = xyz_8_posts.ID
) as 'Presentation Title'


FROM xyz_8_posts
WHERE xyz_8_posts.post_type = "presenters"

我得到一个“子查询返回超过1行”错误。我不明白这是为什么。如果我将WHERE子句中的xyz_8_posts.ID替换为实际ID,则查询将返回一个标题。

您有一个额外的
连接,您只需要一个相关子查询:

SELECT p.ID,
      (select pm.meta_value
       from xyz_8_postmeta pm
       where pm.post_id = p.ID and
             pm.meta_key = 'presentation_title'
      ) as Presentation_Title
FROM xyz_8_posts p
WHERE p.post_type = 'presenters'

首先,内部连接似乎是多余的,另一件事是,可能有一些帖子在元表中有多个条目来表示元键