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 567007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:02:15+00:00 2026-05-13T13:02:15+00:00

Here is a simplified version of my table tbl_records -title -created -views I am

  • 0

Here is a simplified version of my table

tbl_records
-title
-created
-views

I am wondering how I can make a query where they are grouped by title, but the record that is returned for each group is the most recently created. I then will order it by views.

One way I guess is to do a sub query and order it by created and then group it by title and then from those results order it by views. I guess there is a better way though.

Thanks

EDIT:

SAMPLE DATA:

-title: Gnu Design
-created: 2009-11-11 14:47:18
-views: 104

-title: Gnu Design
-created:2010-01-01 21:37:09
-views:9

-title: French Connection
-created:2010-05-01 09:27:19
-views:20

I would like the results to be:

-title: French Connection
-created:2010-05-01 09:27:19
-views:20

-title: Gnu Design
-created:2010-01-01 21:37:09
-views:9

Only the most recent Gnu Design is shown and then the results are ordered by views.

  • 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-05-13T13:02:15+00:00Added an answer on May 13, 2026 at 1:02 pm

    This is an example of the greatest-n-per-group problem that appears frequently on StackOverflow.

    Here’s my usual solution:

    SELECT t1.*
    FROM tbl_records t1
    LEFT OUTER JOIN tbl_records t2 ON (t1.title = t2.title AND 
      (t1.created < t2.created OR t1.created = t2.created AND t1.primarykey < t2.primarykey))
    WHERE t2.title IS NULL;
    

    Explanation: find the row t1 for which no other row t2 exists with the same title and a greater created date. In case of ties, use some unique key to resolve the tie, unless it’s okay to get multiple rows per title.

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

Sidebar

Related Questions

Here's a simplified version of a table I have: sometable title | tag |
I have an html table. Here is a simplified version: <table> <tr> <td><div style=display:
Here's a simplified version of my table. CREATE TABLE TBLAGENT(AGENTID NUMBER, NUMBERSENT NUMBER, AGENTNAME
I have a query that uses the IN clause. Here's a simplified version: SELECT
I have a DataTables table. Here's a simplified version of what I have as
I have this table for documents (simplified version here): id rev content 1 1
Here is a simplified version of my table: group price spec a 1 .
Here is simplified version of my requirement I have a java class say Processor
Here is a simplified version of what I'm trying to do through an expression.
Here is a simplified version of what I have (not working): prog.h: ... const

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.