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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:32:13+00:00 2026-06-15T16:32:13+00:00

I have a simple table called sales with columns createdon, saleid, customerid other table

  • 0

I have a simple table called sales with columns

createdon, saleid, customerid 

other table I have customer table with columns

customerid, name, etc..

now I need last 5 sales by client,

in other table called scanned I have

scannedid,saleid,customerid

I believe I need to have the last 5 salesid by client for I get what clients
were scanned in their last 5 sales ( sales are not same days for example a customer is visited monday a saturday, but other is visited tuesday and thursday but this information is not important for this example)

My real question is

How to get the customersid which were scanned in their last 5 sales?

For that I believe I do need the query for get last 5 salesid by client
for example.i have 3 customers, then i’ll need the last 5 sales, of customer1, customer2, and customer3, then i’ll have 15 saleid returned

  • 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-06-15T16:32:14+00:00Added an answer on June 15, 2026 at 4:32 pm

    By client, I assume you mean customerid. I think you want the first five records from sales, based on the createdon date in descending order. The exact syntax depends on the database. Here is one way:

    select top 5 customerid
    from sales s
    order by createdon desc
    

    And another way:

    select customerid
    from sales s
    order by createdon desc
    limit 5
    

    And another way:

    select *
    from (select customerid, rownum as seqnum
          from sales
          order by createdon
         ) s
    where seqnum <= 5
    

    Now that you’ve clarified what you want, it is easy:

    select *
    from (select s.*,
                 row_number() over (partition by customerid order by created on desc) as seqnum
          from sales s
         ) s
    where seqnum <= 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called keywords. It's simple, two columns - id and keyword.
I have a simple but huge table called 'dictionary' which has 2 columns. Id
I have a table with sales information. One of the columns is called royalty_currency
I have a simple table with just name and email called name_email. I am
I have a simple table called mytable2 with only one column, name as varchar2(20).
I have a very simple table called Member , which consists of the following:
I have a simple ActiveRecord model called Student with 100 records in the table.
I have simple table creating script in Postgres 9.1. I need it to create
Say I have a table called Employee (has ID , NAME , ADDRESS ,
I have a simple SQLite table called message: sequence INTEGER PRIMARY KEY type TEXT

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.