I have this mysql query:
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
I'd like to know how many record this query would return if the LIMIT directive was not there, I googled and found that I needed to add SELECT SQL_CALC_FOUND_ROWS
and SELECT FOUND_ROWS();
MY problem is: I couldn't get it to work:
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()
Assuming this is good idea (I mean doing one query vs two separate ones), how can I get the FOUND_ROWS()
to work with this query?