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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:28:07+00:00 2026-05-13T07:28:07+00:00

I am really bad explaining but I’ll try. Suppose I have with the following

  • 0

I am really bad explaining but I’ll try. Suppose I have with the following tables:

CREATE TABLE inventory (
    Store VARCHAR(16),
    Product_Code INT UNSIGNED,
    Inventory_Qty INT UNSIGNED,
    `Date` DATE
);

CREATE TABLE Alias (
    computername VARCHAR(16),
    storename VARCHAR(32),
);

I want to create a MYSQL query that returns the data based on the last entry in the table. I did it fine with the MAX function based on the date, but I need more advanced in terms of finding the last item entered by a specific product and return the last qty even if it’s not the same date. This is a sample of the data I want as result:

Store| Product| Qty| Date
S1   | 1115   | 10 | 12/30/09  
S2   | 1115   | 20 | 12/30/09  
S3   | 1115   | 5  | 12/29/09  
S4   | 1115   | 15 | 12/28/09  

The query I have is this one, but it is only returning S1 and S2 because I have max on the date, but I want to return the most recent entry of x product by all stores:

Select 
    alias.storename,
    inventory.Product_Code,
    inventory.Inventory_Qty,
    inventory.Date
  From inventory 
    Inner Join Alias On inventory.Store = Alias.computername
  Where inventory.Date = (Select Max(inventory.Date) From inventory)
  Order By Alias.storename, inventory.Product_Code

Any help is really appreciated

  • 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-13T07:28:08+00:00Added an answer on May 13, 2026 at 7:28 am

    Have a look at

    SELECT  i.*
    FROM    (
                SELECT  Store,
                        Product,
                        MAX(Date) MaxDate
                FROM    inventory
                GROUP BY    Store,
                            Product
            ) MaxDates INNER JOIN
            inventory i ON  MaxDates.Store = i.Store
                            AND MaxDates.Product = i.Store
                            AND MaxDates.MaxDate = i.Date
    

    This will firstly get the Max Date per Store per Item and then return that record for which it is the Last entry.

    Let me know if I misunderstood your request.

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

Sidebar

Related Questions

I am having a really bad issue where no matter what I try, the
I have a Website that is really slow and feels really bad when using
I know this is really bad practice, but it's already been put in place
Hi guys I know that this is really bad idea but I want join
How would you begin improving on a really bad system? Let me explain what
If you've ever used SharePoint Designer, you'll know it's bad. Really bad. Is there
Is the documentation for Rich Edit Controls really as bad (wrong?) as it seems
I really like DevX components, but they are pretty expensive, maybe anyone knows free
Really simple question - how do I do a search to find all records
Really stuck on trying to write code to unzip a file or directory on

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.