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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:29:27+00:00 2026-06-05T11:29:27+00:00

I have 2 tables.. a client table..and orders table..i’m trying to get the last

  • 0

I have 2 tables.. a client table..and orders table..i’m trying to get the last 6 orders from each clien, but for all the clients together…i’m having trouble thinking of how to do this haha..it’s friday…any help/ideas? ..i’m using microsoft sql server studio if ya need to know

here is the code i have right now

select /*top 6*/ c.Company_name, oh.qms_control_nbr, c.reminder_notice 
from orderheader oh inner join clients c on oh.prnt_id = c.id
where c.status = 'Active'
group by c.company_name, oh.date_ordered, oh.qms_control_nbr, c.reminder_notice
order by c.company_name asc, c.reminder_notice asc, oh.Date_ordered desc

this give me all the orders for each client, ..just want to limit to last 6

so..it might give results like this

_company_____              __order-num___
company a                     1111
company a                     1112
company a                     1113
company a                     1114
company a                     1115
company a                     1116
company b                     1221
company b                     1222
company b                     1433
company b                     1524
company b                     1345
company b                     1436
  • 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-05T11:29:28+00:00Added an answer on June 5, 2026 at 11:29 am

    You could use the ROW_NUMBER OLAP Function to get this:

    Edit based on new info in question. I think this should get what you’re looking for:

    SELECT c.Company_name, oh.qms_control_nbr, c.reminder_notice 
    FROM (SELECT t.*,
                 ROW_NUMBER() OVER (PARTITION BY prnt_id ORDER BY date_ordered DESC) AS RN
          FROM orderheader t) oh
    JOIN clients c
      ON oh.prnt_id = c.id
    WHERE c.status = 'Active'
      AND oh.rn < 7
    ORDER BY c.company_name asc, c.reminder_notice asc, oh.Date_ordered desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two tables i am trying to get information from. login table -
I have two tables. Table 1: supportstatus clientid company status Table 2: client clientid
I have a a table of clients. I have another of their (many) orders.
Have the following tables: Clients (ID, LastName) Orders (ID, ClientID) Payments (ID, OrderID, PaymentDate,
i have this in my template <% @clients.each do |client| %> <li><%= link_to client.name,
The problem: let's say I have two tables Client , and Product , in
I have those two tables: client: id (int) #PK name (varchar) client_category: id (int)
Our client's request is to have tables in PDF with rounded corner. I only
Lets say I have table with following columns 1. Client - string. 2. Profit
I have 2 tables   1. Client   2. Operations Operations can result in:

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.