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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:03:27+00:00 2026-06-14T15:03:27+00:00

I use mysql 5.1. This is my DB schema : id user_id type created_at

  • 0

I use mysql 5.1.

This is my DB schema :

id     user_id     type     created_at
1       32          X       2012-11-19
2       32          Y       2012-11-18
3       30          X       2012-11-16
4       32          Z       2012-11-17
5       31          Y       2012-11-13
6       32          Z       2012-11-9

I want that my SQL query returns the user_id, type, and the lastest created_at for each type.
I tried to make this request:
SELECT max(type) FROM notification WHERE user_id=34 ORDER BY type but it returns only the latest created_at.

  • 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-14T15:03:29+00:00Added an answer on June 14, 2026 at 3:03 pm

    You cannot do this in really simple query because GROUP BY (which you are missing by the way in your query) doesn’t guarantee that it won’t return values mixed from multiple rows.

    SELECT * FROM notifications AS t1
    INNER JOIN (
        SELECT type, MAX(`created_at`) AS max_created_at
        FROM notification
        WHERE user_id=34
        GROUP BY `type`
    ) AS t2
        ON t1.type = t2.type
            AND t1.created_at = t2.max_created_at
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use this MySQL query: SET @a:=0; UPDATE tbl SET sortId=@a:=@a+1
Is it possible use a MySQL query to perform this kind of check? If
I want to use this C code in my C++ project : mysql.c :
I have stored 6 records in mysql db,when i use this code each of
I've got a locally installed MySQL database server that I want to use for
For clarification, are you able to use MySQL this way to sort? ORDER BY
I'd like to use MySQL in this form: SELECT 1 AS one, one*2 AS
I got a table like this, and use MYSQL 5.5 id --- 2 3
I am trying to use jQuery with MYSQL and I wrote something like this
I'm trying to use the PDO MySQL driver in my CodeIgniter application. This is

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.