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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:21:25+00:00 2026-05-11T20:21:25+00:00

I have the following table: id time text otheridentifier ——————————————- 1 6 apple 4

  • 0

I have the following table:

    id       time      text      otheridentifier
    -------------------------------------------
    1        6         apple     4
    2        7         orange    4
    3        8         banana    3
    4        9         pear      3
    5        10        grape     2

What I want to do is select the 3 most recent records (by time desc), whose otheridentifiers are distinct. So in this case, the result would be id‘s: 5, 4, and 2.

id = 3 would be skipped because there’s a more recent record with the same otheridentifier field.

Here’s what I tried to do:

SELECT * FROM `table` GROUP BY (`otheridentifier`) ORDER BY `time` DESC LIMIT 3

However, I end up getting rows of id = 5, 3, and 1 instead of 5, 4, 2 as expected.

Can someone tell me why this query wouldn’t return what I expected? I tried changing the ORDER BY to ASC but this simply rearranges the returned rows to 1, 3, 5.

  • 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-11T20:21:26+00:00Added an answer on May 11, 2026 at 8:21 pm

    It doesn’t return what you expect because grouping happens before ordering, as reflected by the position of the clauses in the SQL statement. You’re unfortunately going to have to get fancier to get the rows you want. Try this:

    SELECT *
    FROM `table`
    WHERE `id` = (
        SELECT `id`
        FROM `table` as `alt`
        WHERE `alt`.`otheridentifier` = `table`.`otheridentifier`
        ORDER BY `time` DESC
        LIMIT 1
    )
    ORDER BY `time` DESC
    LIMIT 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table of TIME datatypes clarification: I am representing hours/mins/seconds of
I have the following table: mysql> SELECT * FROM `bright_promotion_earnings`; +----+----------+------------+----------+-------+ | id |
I have the following: <table> <tr><td>author's first name</td><td>author's last name</td></tr> <tr><td><input type='text' name='first_name' /></td><td><input
I have the following need: I want to call a js each time an
I have the following table: ThisCategoryID int IDENTITY, AUTO_INCREMENT Title text Type text CategoryID
I have the following table id score start_time end_time 1 60 25 30 2
I have following table Id | Status | date ------------------- 1 | Onsite |2007
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have the following table. When i try to insert records using LINQ to
I have the following table EVENT_LOG : EVENT_ID: pk, int, not null TYPEID: fk,

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.