我有這樣的MySQL查詢:獲得總MySQL的結果從查詢返回了限制:FOUND_ROWS錯誤
SELECT Files.GUID, Files.Name, Files.Type, Files.Visibility, Files.CreationDate, Files.OwnerUser, Date, BackupsCount
FROM Files
LEFT JOIN (
SELECT FileGUID, Date, COUNT(*) AS BackupsCount
FROM Versions
GROUP BY FileGUID
) Versions ON Files.GUID = Versions.FileGUID
WHERE Files.ParentFolder = '96251A8B-B2A8-416B-92D7-3509E6A645C7'
ORDER BY Files.Type DESC, CreationDate ASC
LIMIT 0, 50
我想知道這個查詢需要多少記錄返回如果限制指令是不存在,我用Google搜索,發現我需要添加SELECT SQL_CALC_FOUND_ROWS
和SELECT FOUND_ROWS();
我的問題是:我無法得到它的工作:
SELECT SQL_CALC_FOUND_ROWS * FROM (
SELECT Files.GUID, Files.Name, Files.Type, Files.Visibility, Files.CreationDate, Files.OwnerUser, Date, BackupsCount
FROM Files
LEFT JOIN (
SELECT FileGUID, Date, COUNT(*) AS BackupsCount
FROM Versions
GROUP BY FileGUID
) Versions ON Files.GUID = Versions.FileGUID
WHERE Files.ParentFolder = '96251A8B-B2A8-416B-92D7-3509E6A645C7'
ORDER BY Files.Type DESC, CreationDate ASC
LIMIT 0, 50)
-- Find total rows
SELECT FOUND_ROWS()
假設這是個好主意(我的意思是做一個查詢與兩個單獨的查詢),如何獲得FOUND_ROWS()
以使用此查詢?
謝謝,但我仍然需要行**和**總數。我的意思是添加'SELECT SQL_CALC_FOUND_ROWS'沒有顯示總數,當我運行它 – TheDude
不,它不會;它只存儲**計數,那麼你必須在第二個查詢中檢索它。你可以在一個查詢中做到這一點,但它會花費你...我會盡力改進我的答案。 – LSerni