2015-12-06 178 views
0

我有一個明顯被別人看到的情況,但沒有一個建議的解決方案似乎適用於我的情況。PHP vs MySQL Workbench:同樣的查詢,不同的結果

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條記錄。任何想法爲什麼這可能是這種情況?

回答

0

有查詢之間的輕微differnce:

and a.assessmentscheduledChildID= b.pcnpyChildID; 

and b.pcnpyChildID = a.assessmentscheduledChildID; 

由於您使用tbl1,tbl2加入,而不是通常JOIN聲明,我懷疑MySQL的引擎不同的閱讀。從mysql手冊:

STRAIGHT_JOIN(,)與JOIN類似,不同的是左表爲 總是在右表之前讀取。這可以用於那些(少數) 情況,其中連接優化程序以錯誤的順序放置表。

相關問題