PHP与MySQL Workbench:相同的查询,不同的结果

时间:2015-12-06 20:31:08

标签: php mysql

我有其他人明显看到的情况,但所提出的解决方案似乎都不适用于我的情况。

MySQL QUERY

select a.assessmentscheduledID, a.assessmentscheduledHVID, a.assessmentscheduledChildID, a.assessmentscheduledType, a.assessmentscheduledAssessmentID, a.assessmentscheduledDateSubmitted, b.pcnpyCurricYearID, b.pcnpyCurricLang from `hhpip_chairs`.tblAssessmentsScheduled a, `hhpip_chairs`.tblPCNPY b where a.assessmentscheduledAAStatus = 2 and a.assessmentscheduledAADistYN = 0 and a.assessmentscheduledChildID= b.pcnpyChildID;

在工作台中,此查询164记录。

PHP代码

$getassessout = "select a.assessmentscheduledID, a.assessmentscheduledHVID, a.assessmentscheduledChildID, a.assessmentscheduledType, a.assessmentscheduledAssessmentID, a.assessmentscheduledDateSubmitted, b.pcnpyCurricYearID, b.pcnpyCurricLang from tblAssessmentsScheduled a, tblPCNPY b where a.assessmentscheduledAAStatus = 2 and a.assessmentscheduledAADistYN = 0 and b.pcnpyChildID = a.assessmentscheduledChildID";
$getassessoutresults = $mysqli->query($getassessout) or trigger_error("<p class=\"error\">We're very sorry, but an error has occurred when interacting with the CHAIRS database.  Please try again and see if the error repeats.  If it does, please get the following information in its entirety to your database administrator so the CHAIRS developer can get the error resolved.<br />Error Message: " . $mysqli->error, E_USER_ERROR);

当我的网页上运行此代码时,我会收到152条记录。有关为什么会出现这种情况的任何想法?

1 个答案:

答案 0 :(得分:0)

查询之间略有不同:

and a.assessmentscheduledChildID= b.pcnpyChildID;

and b.pcnpyChildID = a.assessmentscheduledChildID;

由于您使用tbl1,tbl2加入而不是通常的JOIN语句,我怀疑mysql引擎正在以不同方式读取它。从mysql手册:

  

STRAIGHT_JOIN(,)与JOIN类似,只是左表是   总是在正确的桌子前阅读。这可以用于那些(少数)   连接优化器将表放入错误顺序的情况。