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

  • Home
  • SEARCH
  • 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 869399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:17:57+00:00 2026-05-15T10:17:57+00:00

Ok, so here’s the issue. Currently I’m using the symfony framework to develop a

  • 0

Ok, so here’s the issue. Currently I’m using the symfony framework to develop a web app. I’m using MySQL in the backend but want to keep my queries in their doctrine format to avoid any problems if I ever need to change databases.

In one section of the web application I’m looking for the last comment associated by any distinct user, sorted by the date. There can be multiple comments from many users all on the same date and time, but this query should only grab the last comment based on the date.

 comments table
 -----------------------------------------------------------------
 | comment_id  |  user_id   | comment      |  date_time          |
 -----------------------------------------------------------------
 |    1        |    2       |  Test_1      | 2010-01-01 00:00:00 |
 |    2        |    2       |  Test_2      | 2010-02-01 00:00:00 |
 |    3        |    2       |  Test_3      | 2010-03-01 00:00:00 |
 |    4        |    4       |  Test_4      | 2010-04-01 00:00:00 |
 |    5        |    4       |  Test_5      | 2010-05-01 00:00:00 |
 |    6        |    4       |  Test_6      | 2010-06-01 00:00:00 |
 |    7        |    3       |  Test_7      | 2010-07-01 00:00:00 |
 |    8        |    2       |  Test_8      | 2010-08-01 00:00:00 |
 |    9        |    3       |  Test_9      | 2010-09-01 00:00:00 |
 -----------------------------------------------------------------

Above is an example table. The query I run should return the data as follows.

 -----------------------------------------------------------------
 | comment_id  |  user_id   | comment      |  date_time          |
 -----------------------------------------------------------------
 |    9        |    3       |  Test_9      | 2010-09-01 00:00:00 |
 |    8        |    2       |  Test_8      | 2010-08-01 00:00:00 |
 |    6        |    4       |  Test_6      | 2010-06-01 00:00:00 |
 -----------------------------------------------------------------

The least amount of sub queries would obviously be better. It would be possible that the date_time could be lower on a future comment by a user.

It seems simple but it is proving rather difficult…

  • 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-15T10:17:58+00:00Added an answer on May 15, 2026 at 10:17 am

    Unfortunately I don’t know Doctrine syntax but I can give you a solution in SQL. This SQL query is tested in MySQL but should also work in many other databases:

    SELECT comment_id, user_id, comment, date_time
    FROM comments
    WHERE comment_id IN (
        SELECT MAX(comment_id) AS comment_id
        FROM comments T1
        JOIN
        (
            SELECT user_id, MAX(date_time) AS date_time
            FROM comments
            GROUP BY user_id
        ) T2
        ON T1.user_id = T2.user_id AND T1.date_time = T2.date_time
        GROUP BY T1.user_id, T2.date_time
    )
    

    If someone else here wants to write an answer for doctrine they are welcome to use this as a starting point if it is of any help.

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

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since phone numbers must conform to a pattern, you can… May 15, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer The build method initializes a new ActiveRecord object, but does… May 15, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer A CALayer can be animated trivially in this way. If… May 15, 2026 at 2:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.