PHP 与 MySQL Workbench : Same query, 不同的结果

标签 php mysql

我遇到了其他人显然看到的情况,但建议的解决方案似乎都不适用于我的情况。

MySQL 查询

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 条记录。对于为什么会出现这种情况有什么想法吗?

最佳答案

查询之间存在细微差别:

and a.assessmentscheduledChildID= b.pcnpyChildID;

and b.pcnpyChildID = a.assessmentscheduledChildID;

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

STRAIGHT_JOIN(,) is similar to JOIN, except that the left table is always read before the right table. This can be used for those (few) cases for which the join optimizer puts the tables in the wrong order.

关于PHP 与 MySQL Workbench : Same query, 不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34122355/

相关文章:

php - 通过前端(HTML、CSS、PHP、SQL)编辑信息和更新数据库

php - MP4 到 OGG 的转换不包括声音

php - 具有多个 AND/OR 的 Yii 条件 - 运算符优先级

mysql - MySQL 中的 SELECT DISTINCT 和 ORDER BY

mysql - 使用变量更新触发器中的 SQL 语法错误

php - MongoDB 作为 MySQL 缓存

php - 限制查询结果

mysql - MySQL 中的对计数

mysql - 分别更新每一行

php - 从表中调用 ID