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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:19:13+00:00 2026-06-01T14:19:13+00:00

Using the following query I am looking for a solution to get the latest

  • 0

Using the following query I am looking for a solution to get the latest record that having some conditions.
But it gives me the first record, not the latest. I think its only considering the group by
Please advise me

SELECT * FROM `contacts` WHERE `id_receiver`=1  GROUP BY `id_thread` ORDER BY created DESC

id   id_sender   id_thread sender_email   id_receiver      created(datetime)
1    2             2         51             1                2012-03-24 13:44:48
2    4             4         1              5                 2012-04-26 13:46:05
3    2             2         51             1                2012-04-09 12:12:30

Required output

id   id_sender  id_thread sender_email   id_receiver      created(datetime)
3    2           2         51             1                2012-04-09 12:12:30

I had done a test just swap the order by and group by , giving me an erros.

Anybody can just look in to this?. Thanks.

EDIT Edited question, forget to write id_thread

  • 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-01T14:19:14+00:00Added an answer on June 1, 2026 at 2:19 pm

    How can you GROUP BY id_thread when there is no id_thread column in your table?

    SELECT * 
    FROM contacts 
    WHERE id_receiver = 1 
                                     --- GROUP BY id_thread
                                     --- removed 
    ORDER BY created DESC
    LIMIT 1                          --- only show one row
    

    Based on your comments, what you want is the latest (ordered by created) row for every id_thread, which is a different and more complex query. There’s even a tag for this kind of queries, named [greatest-n-per-group].

    SELECT c.* 
    FROM contacts AS c
      JOIN
        ( SELECT id_thread, MAX(created) AS created 
          FROM contacts 
          WHERE id_receiver = 1  
          GROUP BY id_thread
        ) AS g 
        ON (g.id_thread, g.created) = (c.id_thread, c.created) 
    WHERE c.id_receiver = 1  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that when using the following NHibernate query, I do not get a
Using Oracle 11g release 2, the following query gives an ORA-01790: expression must have
Looking to run a query using multiple left joins. The following query works. SELECT
Using the following query and results, I'm looking for the most recent entry where
I'm looking for a query to get the following output: Id Number -- ------
I am using following query which works fine for me except one problem SELECT
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
I am using following SQL Query: SELECT `comment`.`id` AS `comment_id` , count( `comment_likes`.`comment_id` )
I'm using the following query to perform a search in SQLite. public MatrixCursor listViewCursor(String
I'm using the following query: INSERT INTO role (name, created) VALUES ('Content Coordinator', GETDATE()),

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.