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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:51:05+00:00 2026-05-24T16:51:05+00:00

i have this table id | title | amount | timestamp 1 | random1

  • 0

i have this table

id |   title   | amount | timestamp
1  |  random1  |   150  | 1313635011
2  |  random2  |   190  | 1313635730
3  |  random2  |   210  | 1313637359
4  |  random2  |   100  | 1313691807
5  |  random3  |   130  | 1313692673
6  |  random4  |   900  | 1313692739
7  |  random4  |   111  | 1313692988

i want to get this result (rows with different titles and biggest timestamps):

id |   title   | amount | timestamp
1  |  random1  |   150  | 1313635011
4  |  random2  |   100  | 1313691807
5  |  random3  |   130  | 1313692673
7  |  random4  |   111  | 1313692988

i have this query.

SELECT * FROM (
  SELECT * FROM table ORDER BY timestamp DESC 
) m GROUP BY title

It works as charm but can this be converted to a JOIN statement?

Thanks

  • 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-24T16:51:05+00:00Added an answer on May 24, 2026 at 4:51 pm

    This can be simplified to the following (the ORDER BY in the subquery is useless):

    SELECT * 
    FROM table
    GROUP BY title
    

    Why do you think that you need JOIN? (Ok, this was resolved by comments).


    After your comment that you need for every title, the row with biggest timestamp, this would do the work:

    SELECT t.* 
    FROM
        table AS t
      JOIN
        ( SELECT title
               , MAX(timestamp) AS maxts
          FROM table
          GROUP BY title
        ) AS grp
        ON grp.title = t.title
        AND grp.maxts = t.timestamp
    ORDER BY t.timestamp DESC
    

    For the record, your original query:

    SELECT * 
    FROM 
      ( SELECT * 
        FROM table 
        ORDER BY timestamp DESC 
      ) m
    GROUP BY title
    

    might work as expected, but: only in MySQL that allows you to use in the SELECT list fields that are not in the GROUP BY clause (or depend on those), without any aggregate functions in them. So, the above query will return a more or less random row for every title. In fact, it will return the first row it will find for a title. So, having first run the subquery (which orders by timestamp DESC) results in finding first the row with biggest timestamp.

    This however, only happens because (when, if) the optimizer does not understand that the subquery is useless. You may find that your original query runs fine when one day you upgrade to MySQL version 7.5 and your query stops working as before. (because the optimizer got more clever and translated your query to a simpler without sub-select).

    You may even find your query to stop working altogether and produce error if MySQL decides in a future release to be in terms with SQL standards for the GROUP BY queries.

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

Sidebar

Related Questions

I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
i have this three tables. Table: Item Columns: ItemID, Title, Content, NoChange (Date) Table:
I have a table with contents that look similar to this: id | title
I have a table posts that could look like this: id | title |
I use Postgresql + PHP. Say I have this table: Books ( id, title,
I have such this table: position title --------------------------- 1 t1 2 t1 3 t2
I have a table like this (MySQL 5.0.x, MyISAM): response{id, title, status, ...} (status:
Say for example I have this table: Items: ------- id title price And I
I have this table in an Oracle DB which has a primary key defined
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT

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.