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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:19:26+00:00 2026-05-30T14:19:26+00:00

Users +——–+————–+———-+————–+ | userID | userUsername | userName | userLastName | +——–+————–+———-+————–+ | 6

  • 0

Users

+--------+--------------+----------+--------------+
| userID | userUsername | userName | userLastName |
+--------+--------------+----------+--------------+
|      6 | richard      | Ricardo  | Vega         |
|     10 | jason        | Jason    | Bourne       |
+--------+--------------+----------+--------------+

Restocks

+-----------+-------------+--------+--------+-----------------+
| restockID | restockDate | itemID | userID | restockQuantity |
+-----------+-------------+--------+--------+-----------------+
|         1 | 2012-02-29  |      1 |      6 |              48 |
|         2 | 2012-02-29  |      1 |     10 |             100 |
|         3 | 2012-02-29  |      2 |     10 |              50 |
|         4 | 2012-02-29  |      2 |      6 |             100 |
|         5 | 2012-02-29  |      2 |      6 |             200 |
|         6 | 2012-02-29  |      2 |     10 |            2000 |
|         7 | 2012-02-29  |      1 |     10 |            2000 |
+-----------+-------------+--------+--------+-----------------+

Items

+--------+--------------------+
| itemID | itemName           |
+--------+--------------------+
|      1 | Coca Cola (lata)   |
|      2 | Cerveza Sol (lata) |
+--------+--------------------+

Ok guys, i have supplied some sample data as requested. I need to get this table:

+--------+--------------------+---------------+-------------+----------+--------------+--------------+
| itemID | itemName           | itemExistence | restockDate | userName | userLastName | userUsername |
+--------+--------------------+---------------+-------------+----------+--------------+--------------+
|      2 | Cerveza Sol (lata) |          2350 | 2012-02-29  | Jason    | Bourne       | jason        |
|      1 | Coca Cola (lata)   |          2148 | 2012-02-29  | Ricardo  | Vega         | richard      |
+--------+--------------------+---------------+-------------+----------+--------------+--------------+

But, i need restockDate to be THE LATEST ONE for each itemName. In the example, it shows the first restock and not the latest one. I just need to show what’s the existence for the item and when was restocked for last time, not first time.

If my tables are not good or so, please suggest a new schema.

I know maybe this is a lot so i will tip 5 USD (Paypal) to the one how can help me with this. Promise.

  • 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-30T14:19:27+00:00Added an answer on May 30, 2026 at 2:19 pm

    As discussed in comments, many restocks can be performed on the same day so it is not possible to compare dates in this case. Two options are presented here: Use the incremental PK from restocks table or restructure the table. For the first case, this is the solution:

    select i.itemID, i.itemName, i.itemExistence, r.restockDate, u.userName,
      u.userLastName, u.userUsername
    from items i
    left join (
        select r1.restockDate, r1.itemID, r1.userID from restocks r1
        left join restocks r2
        on r1.itemId = r2.itemId and r1.restockId < r2.restockId
        where r2.restockDate is null
    ) as r on i.itemID = r.itemID
    inner join users u on r.userID = u.userID
    

    For the second case, the restructre would imply changing the date field to a unique datetime that would uniquely identify a record. That is the best solution, however, it does require to also update any previous data present in the table. That means, to update all the records that have the same date for a single product restock and set different date times to them.

    The lazy one (like me), would go for the first option 🙂 Let me know if you have any doubt about this.

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

Sidebar

Related Questions

users table +-----+-----------+ | id | username | +-----+-----------+ | 1 | tom |
Users can access others users profiles like this: site.com/username My find method in my
Users table user_id pic_url name friends table auto_id userid friendid status actions table auto_id
Users Table user_id username thumb_id fullimage_id 1 jprescott 14 15 2 lpausch 18 19
Users UserGroup id name rowid GrpID UserID name 1 aaa 1 1 1 aaa
Users are pasting text from Lotus Notes into my VBA application. This is then
Users on my site can add nodes of a custom type (let's call it
Users on my site can post news items. But right now, it's all honor
Users of our website often type in a lot of garbage for the name
Users drag rows up and down in my DataGridView. I have the dragging logic

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.