在php中为带有联接的查询返回SQL错误

在php中为带有联接的查询返回SQL错误,php,html,mysql,Php,Html,Mysql,我试图通过对php应用程序执行以下查询来填充表: $sql3 = "SELECT distinct(`t1.testName`), `t2.comments AS C1` from `sample AS t1` left join `sample AS t2` ON `t1.testName`= `t2.testName` where `t1.buildNumber`= 181 and `t2.buildNumber`= 180 and `t1.errorStackTrace` is not n

我试图通过对php应用程序执行以下查询来填充表:

$sql3 = "SELECT distinct(`t1.testName`), `t2.comments AS C1` from `sample AS t1` left join `sample AS t2` ON `t1.testName`= `t2.testName` where `t1.buildNumber`= 181 and `t2.buildNumber`= 180 and `t1.errorStackTrace` is not null";

$result3 = mysqli_query($dbconnect,$sql3);

if(!mysqli_query($dbconnect, $sql3)){
    printf("error message: %s\n",mysqli_error($dbconnect));
}
我看到返回了以下错误:

error message: Table 'testdata.sample as t1' doesn't exist
我已经尝试了很多方法来解决这个问题,但是没有成功。在mysql上运行时,查询运行良好。 任何帮助都将不胜感激。
谢谢

您将表名转义错误。使用此原始查询:

SELECT DISTINCT(t1.testName),
       t2.comments AS C1
FROM `sample` AS t1
LEFT JOIN `sample` AS t2
    ON t1.testName = t2.testName
WHERE t1.buildNumber = 181 AND
      t2.buildNumber = 180 AND
      t1.errorStackTrace IS NOT NULL
我认为你真的不需要在任何地方回击。但在任何情况下,只需要在列名上打勾,而不需要使用别名,例如

t1.`testName` but NOT `t1.testName`

您正在错误地转义表名。使用此原始查询:

SELECT DISTINCT(t1.testName),
       t2.comments AS C1
FROM `sample` AS t1
LEFT JOIN `sample` AS t2
    ON t1.testName = t2.testName
WHERE t1.buildNumber = 181 AND
      t2.buildNumber = 180 AND
      t1.errorStackTrace IS NOT NULL
我认为你真的不需要在任何地方回击。但在任何情况下,只需要在列名上打勾,而不需要使用别名,例如

t1.`testName` but NOT `t1.testName`

错误的反向报价,请尝试以下操作:

$sql3 = "SELECT distinct(t1.`testName`), t2.`comments` AS C1 from `sample` AS t1 left join `sample` AS t2 ON t1.`testName`= t2.`testName` where t1.`buildNumber`= 181 and t2.`buildNumber`= 180 and t1.`errorStackTrace` is not null";

错误的反向报价,请尝试以下操作:

$sql3 = "SELECT distinct(t1.`testName`), t2.`comments` AS C1 from `sample` AS t1 left join `sample` AS t2 ON t1.`testName`= t2.`testName` where t1.`buildNumber`= 181 and t2.`buildNumber`= 180 and t1.`errorStackTrace` is not null";

只能在表名或列名周围使用反勾号,不包括别名:

$sql3 = "SELECT distinct(`t1`.`testName`), `t2`.`comments` AS C1 from `sample` AS ` left join `sample` AS t2 ON t1.testName= t2.testName where t1.buildNumber= 181 and t2.buildNumber= 180 and t1.errorStackTrace is not null";

只能在表名或列名周围使用反勾号,不包括别名:

$sql3 = "SELECT distinct(`t1`.`testName`), `t2`.`comments` AS C1 from `sample` AS ` left join `sample` AS t2 ON t1.testName= t2.testName where t1.buildNumber= 181 and t2.buildNumber= 180 and t1.errorStackTrace is not null";

使用正确的反引号或删除
$sql3=“选择不同的(t1.testName),t2.comments作为C1从样本作为t1左连接样本作为t2在t1.testName=t2.testName,其中t1.buildNumber=181和t2.buildNumber=180,t1.errorStackTrace不为空”
使用正确的反引号或删除
$sql3=“选择不同的(t1.testName),t2.comments作为C1从样本作为t1左连接样本作为t2在t1.testName=t2.testName,其中t1.buildNumber=181和t2.buildNumber=180,t1.errorStackTrace不为null”