I have a blog SQL system with ‘posts’ table like this (id, theme, title, content, created).
I would like to get the last 3 titles of each post theme, to display in a table, but I didn’t get it.
I tried this SQL code:
SELECT *
FROM posts
GROUP BY theme
ORDER BY created DESC
LIMIT 0,3
But this gives me the last 3 posts of the table!!!
Can you please help me?
Thanks in advance.
Josvic Zammit’s answer is in parts right (+1 from me) but you don’t have to perform the query per theme. This is a way you can do it in MySQL, although it would surely be easier to “perform the query per theme” in PHP or whatever.
Note that I unfortunately can’t test it right now, but it should work. Also note, that this query might be slower than performing a simpler query per theme.