Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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 左连接同一字段选择所有行_Php_Mysql_Sql_Pdo - Fatal编程技术网

Php 左连接同一字段选择所有行

Php 左连接同一字段选择所有行,php,mysql,sql,pdo,Php,Mysql,Sql,Pdo,如何选择表UsrArticle中UsrId=1的行? 我是新使用join的,下面是我的代码,有什么问题吗?它只打印空数组 表Usr id UsrId 0 0 1 1 2 2 3 3 表UsrArticle ArticleId UsrId 0 1 1 0 2 1 3 1 4 1 5 3 php 它将失败,因为UsrID是不明确的,您所

如何选择表UsrArticle中UsrId=1的行? 我是新使用join的,下面是我的代码,有什么问题吗?它只打印空数组

表Usr

id    UsrId
0     0
1     1
2     2
3     3
表UsrArticle

ArticleId   UsrId
0           1
1           0
2           1
3           1
4           1
5           3
php


它将失败,因为UsrID是不明确的,您所指的列有多种可能性。我知道这很愚蠢,因为您的条件指定它们应该相同,但SQL就是这样工作的。将表别名添加到该字段名的前缀:

... WHERE Usr.UsrId = :UsrId

谢谢你的回复。你的意思是我必须像SELECT*FROM Usr LEFT那样在Usr.UsrId=UsrArticle.UsrId上加入UsrArticle,其中Usr.UsrId=:UsrId
... WHERE Usr.UsrId = :UsrId