I have 3 tables: posts, tags, *posts_tags* . I want to list posts, and all tags associated with them, but to limit the results.
This is what I do now:
SELECT
p.*,
t.*
FROM
(
SELECT * FROM posts LIMIT 0, 10
) as p
LEFT JOIN
posts_tags as pt
ON pt.post_id = p.post_id
LEFT JOIN
tags as t
ON t.tag_id = pt.tag_id
It is working fine, but it seems to be a little bit slow..
Is there a better/faster way of doing this? Can I apply LIMIT somewhere else for better results?
EDIT: I want to limit posts, and not results. A post can have many tags.
Have you tried moving the limiting subquery to the where clause instead: