Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:48:42+00:00 2026-06-02T20:48:42+00:00

I have a blog SQL system with ‘posts’ table like this (id, theme, title,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:48:45+00:00Added an answer on June 2, 2026 at 8:48 pm

    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.

    SELECT * FROM
    (
    SELECT
    IF(@prev != sq.theme, @rownum:=1, @rownum:=@rownum + 1) AS rownumber, @prev:=sq.theme, sq.*
    FROM
    (
        SELECT
        *
        FROM
        posts
        , (SELECT @rownum:=0, @prev:=0) r 
        ORDER BY theme, created DESC
    ) sq
    ) q
    WHERE q.rownumber <= 3
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ASP.net and an SQL database. I have a blog like system where
I have a blog installed in www.foo.com/wp/ and would like all requests that go
I'm trying to setup a date lookup table as in this: http://www.techrepublic.com/blog/datacenter/simplify-sql-server-2005-queries-with-a-dates-table/326 but the
I have default value getdate() in the blog table in SQL Server database In
I have read plenty of blog posts and have yet to find a clear
I would like to perform LINQ to SQL mapping in C#, in a many-to-many
I'm just having this trouble with Wordpress: I use to have a Blog with
I'm working on a blog in PHP/SQL etc and I have come across something
I have a (Wordpress) blog and some of my older posts have a character
I need to set up a queue system using some SQL tables, like the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.