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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:47:01+00:00 2026-05-26T23:47:01+00:00

Hello StackOverflow community, I have 2 tables products ======= id name prices ====== id

  • 0

Hello StackOverflow community,

I have 2 tables

products
=======
id
name

prices
======
id
product_id
price
date_added

The column ‘date_added’ is of DATETIME type.

My question is how can I select the products.name, prices.price, prices.date_added where the date_added is maximum.

The result set should contain 1 row per product with the price and the max date_added.

Please let me know if this is not understandable enough!

HERE IS A SET OF RECORDS

INSERT INTO `prices` (`id`, `product_id`, `price`, `date_added`) VALUES
(1, 1, 1.23, '2011-11-16 13:18:14'),
(2, 1, 1.25, '2011-11-17 13:18:24'),
(3, 2, 1.5, '2011-11-15 13:18:32'),
(4, 3, 1.89, '2011-11-15 13:18:41'),
(5, 4, 0.98, '2011-11-14 13:18:57'),
(6, 5, 1.87, '2011-11-17 13:19:29'),
(7, 5, 1.98, '2011-11-16 13:19:44'),
(8, 3, 1.87, '2011-11-13 13:19:52'),
(9, 2, 1.45, '2011-11-05 13:20:01'),
(10, 1, 2.34, '2011-11-16 13:20:10'),
(11, 4, 2.87, '2011-11-18 13:49:21'),
(12, 5, 1.64, '2011-11-19 13:49:33');

INSERT INTO `products` (`id`, `name`) VALUES
(1, 'Karamhtros'),
(2, 'Tralalas'),
(3, 'Giwrgos'),
(4, 'Sotiris'),
(5, 'Tassos');
  • 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-26T23:47:02+00:00Added an answer on May 26, 2026 at 11:47 pm

    Try this

    SELECT p.name, pr.price, pr.date_added
    FROM products p INNER JOIN prices pr
      ON p.id = pr.product_id
    GROUP BY p.id
    HAVING pr.date_added = MAX(pr.date_added)
    

    EDITED after user comment:
    Try this one

    SELECT p.id, p.name, pr.price, pr.date_added
    FROM products p INNER JOIN prices pr
      ON p.id = pr.product_id
    INNER JOIN (SELECT product_id, MAX(date_added) AS da 
                FROM prices GROUP BY product_id) pr2
      ON pr.product_id = pr2.product_id AND pr.date_added = pr2.da
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello StackOverflow community, I have run into a problem that quite frankly is baffling
Hello wonderful stackoverflow users. I have a question about url loading. In many browsers
Hello Stackoverflow users, I have a question regarding an JQ UI widget im trying
Hello stackoverflow community ! I am trying to figure out how to architect my
Hello StackOverflow community, Using Google App Engine, I wrote a keyToSha256() method within a
Hello StackOverflow'ers, I have a (flex) app that, on the click of a button,
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Hello StackOverflow community, The air.swf file referenced here: http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html used to launch AIR applications
Hello StackOverflow community, Is there any way to open a folder in Windows Explorer

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.