I'm trying to convert my SELECT
query into a faster version of SELECT
including JOIN
, that I found online.
Here is my code:
$stmt->prepare("SELECT * FROM books WHERE person_id = :person_id ORDER BY id DESC LIMIT 5, 10");
convert to:
SELECT l.id, value, LENGTH(stuffing) AS len
FROM (
SELECT id
FROM t_limit
ORDER BY
id
LIMIT 150000, 10
) o
JOIN t_limit l
ON l.id = o.id
ORDER BY
l.id
I found that code online (last piece of code). Its supposed to help with performance when doing OFFSET
and LIMIT
. anyways... here is what i tried:
$stmt->prepare("SELECT * FROM (SELECT id FROM books WHERE person_id = :person_id ORDER BY id DESC LIMIT 5, 10) o WHERE person_id = :person_id JOIN books l ON l.id = o.id ORDER BY l.id");
but it does not seem to work.
any help would be appreciated!