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
You could use the
ROW_NUMBEROLAP Function to get this:Edit based on new info in question. I think this should get what you’re looking for: