I need to select all posts with all their related tags:
SELECT p.*, pt.name AS tag_name, pt.id AS tag_id FROM posts p
LEFT JOIN posts_tags pt ON pt.post_id = p.id
So i get something like this:
p.id | p.name | p.content | tag_name | tag_id
1 | Yahoo | ... | first | 1
1 | Yahoo | ... | second | 2
2 | Google | ... | second | 2
2 | Google | ... | third | 3
I know when selecting records this way it is possible to get number of records through COUNT(p.id) for example, but i didn’t discover how to set OFFSET (how many records skip from the beginning) and LIMIT (how many records return at all) according to unique post ID.
Now it’s obviously working in the way, that it’s skipping/limiting the number of records, but not the number of real posts…
If I understand you correctly, you want all “tag” rows for N posts starting at offset O:
Addendum
Here’s one way to do it using
DENSE_RANKto limit just by the posts themselves: