Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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
Php mysql-从两个表中选择多个列值_Php_Mysql - Fatal编程技术网

Php mysql-从两个表中选择多个列值

Php mysql-从两个表中选择多个列值,php,mysql,Php,Mysql,我需要为给定的帖子选择帖子内容和图片 我有一个post和image表,我想根据postid从这两个表中选择一些列/不是所有列 我这样做,但得到语法错误 SELECT `title`,`desc`,`date`, FROM `img`.`post` INNER JOIN (SELECT `hash`,`hits`,`timestamp`,`userid` FROM `img`.`image` WHERE `postid` IS NOT NULL) WHERE `postid` IS

我需要为给定的帖子选择帖子内容和图片

我有一个
post
image
表,我想根据
postid
从这两个表中选择一些列/不是所有列

我这样做,但得到语法错误

SELECT `title`,`desc`,`date`, FROM `img`.`post` 
INNER JOIN 

    (SELECT `hash`,`hits`,`timestamp`,`userid` FROM `img`.`image` WHERE `postid` IS NOT NULL)

WHERE `postid` IS NOT NULL
请查看并建议任何可能的方法。
谢谢

删除表名之前的

 SELECT `title`,`desc`,`date`,
您需要创建表的别名

SELECT `title`,`desc`,`date` FROM `img`.`post` 
INNER JOIN 

    (SELECT `hash`,`hits`,`timestamp`,`userid`,`postid` FROM `img`.`image` WHERE `postid` IS NOT NULL) 

AS a

WHERE a.`postid` IS NOT NULL

如果使用内部联接,则不必使用is not null条件,因为它将只返回匹配值

请提供一些示例数据和预期输出。两个表中的公共属性是什么?现在我得到
(!)致命错误:每个派生表都必须在
I获得未知列a中有自己的别名。
postid
您需要在select语句中添加
postid
!!检查updatedHI,如何从预付费声明中的子查询
a
中获取结果?我不理解您的问题
   SELECT `p.title`,`p.desc`,`p.date`,`im.hash`,`im.hits`,`im.timestamp`,`im.userid` FROM `post` as p 
    INNER JOIN `image` as im ON p.postid =im.postid