[英]PHP vs MySQL Workbench: Same query, different results
I have a situation apparently seen by others, but none of the solutions suggested seem to apply to my situation. 我的情况显然已被其他人看到,但是建议的解决方案似乎都不适用于我的情况。
MySQL QUERY 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;
In workbench this query 164 records. 在工作台中,此查询164条记录。
PHP Code 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);
When this code runs on my web page, I get back 152 records. 当此代码在我的网页上运行时,我获得了152条记录。 Any thoughts on why this may be the case?
有什么想法为什么会这样呢?
There is a slight differnce between the queries: 查询之间略有不同:
and a.assessmentscheduledChildID= b.pcnpyChildID;
and b.pcnpyChildID = a.assessmentscheduledChildID;
Since you are using tbl1,tbl2
to join instead of the usual JOIN
statement , I suspect the mysql engine is reading it differently. 由于您使用的是
tbl1,tbl2
而不是通常的JOIN
语句,所以我怀疑mysql引擎在读取它的方式有所不同。 From the mysql manual : 从mysql手册:
STRAIGHT_JOIN(,) is similar to JOIN, except that the left table is always read before the right table.
STRAIGHT_JOIN(,)与JOIN相似,不同之处在于始终在右表之前读取左表。 This can be used for those (few) cases for which the join optimizer puts the tables in the wrong order.
这可以用于联接优化器将表以错误的顺序放置的那些(很少)情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.