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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:19:16+00:00 2026-05-16T12:19:16+00:00

can anyone generate a query for me. Lets say i have a table sales(saleID,

  • 0

can anyone generate a query for me.
Lets say i have a table sales(saleID, date_of_sales, customerID, itemID, saleprice)

  • date_of_sales is the datetime field which stores the time of the sale.

  • customerID is self exlpaining tells to whom item was sold.

  • itemID is ID of the item sold.

  • saleprice is the price that the item was sold.

I want to construct a query which will give out the detail of the last purchase by each customers. this could be done by using date_of_sales.

Example table

saleID | date_of_sales | customerID | itemID | saleprice

101 | 2008-01-01 | C2000 | I200 | 650 |
102 | 2010-01-01 | C2000 | I333 | 200 |
103 | 2007-01-01 | C3333 | I111 | 800 |
104 | 2009-12-12 | C3333 | I222 | 100 |

this is the example data table, there are only two customer for simplicity.

  • customer C2000 did his last purchase
    on 2010-01-01

  • customer C3333 did his last purchase
    on 2009-12-12

I want to get a result like this

customerID | date_of_sales | itemID | saleprice

C2000 | 2010-01-01 | I333 | 200 |

C3333 | 2009-12-12 | I222 | 100 |

  • 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-16T12:19:17+00:00Added an answer on May 16, 2026 at 12:19 pm

    This might be what you are looking for…

    SELECT *
        FROM sales
        WHERE sales.date_of_sales = (SELECT MAX(date_of_sales)
                                         FROM sales s2
                                         WHERE s2.customerID = sales.customerID);
    

    There is a slight problem with it; if there were two sales on the same day to the same customer, you’ll get two rows (unless your date-of-sales column includes the time as well). I think the same applies to the answer above, though.

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

Sidebar

Related Questions

Anyone have a PL-SQL statement that i can use to generate database & tables
can anyone tell me how to generate form dynamically in Dotnet from xml file.
Can anyone tell me why this would generate a syntax error in Safari and
I want to generate graph from my database data can anyone tell me about
Can anyone tell me why ActionScript 3, a statically typed language, doesn't have generics?
Can anyone help? I have been using the entity framework and its going well
Let's say I have a table named transaction with transaction_date, deposit, withdrawal fields. There
I have an ASP page which will query records from a DB Table and
In sql server 2005/2008, can anyone please advise me on how can i generate
Can anyone save me? I have the following code: private List<string> GenerateTerms(string[] docs) {

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.