I'm not sure of the best way to phrase the questions, but I'll do my best.
To simplify, lets say I have a db with 50 tbls, some containing transaction histories for a customer's product orders and options. I have a qry that produces one record per order. so far so good. What I need to figure out is, for a given order with 0 to n product options (say tblOptions.ID, tblOptions.Name), how to distinguish the 1st, 2nd, 3rd and 4th option even if there are say 8 or 12 or any n options. Min and max work fine at the extremes, but I need to have the 1st 4 fields only in the resulting record to denote the options in sequence. I did figure something out that gave me the record before the max, but for this problem I realy need the 1st through 4th, not the 4th through the 1st, since there could in theory be any number of options from 0 to whatever. The query I've built so far makes great use of subqueries and nexted subqueries. I recently discovered them and was intrigued, likely not that efficent yet. Anyway, I added one field with a number of nested subqueries to get the 2nd option, and it was soooooo slow.
Can anyone point me in the right direction for an sql subquery for sequencing in separate fields?
i.e. I have
Cust1, prod1, option1
Cust1, prod1, option2
Cust1, prod1, option3
Cust1, prod1, option4
Cust2, prod1
Cust3, prod1, option1
Cust3, prod1, option2
Cust4, prod1, option1
and I want:
Cust1, prod1, option1, option2, option3, option4
Cust2, prod1
Cust3, prod1, option1, option2
Cust4, prod1, option1
Thanks!
To simplify, lets say I have a db with 50 tbls, some containing transaction histories for a customer's product orders and options. I have a qry that produces one record per order. so far so good. What I need to figure out is, for a given order with 0 to n product options (say tblOptions.ID, tblOptions.Name), how to distinguish the 1st, 2nd, 3rd and 4th option even if there are say 8 or 12 or any n options. Min and max work fine at the extremes, but I need to have the 1st 4 fields only in the resulting record to denote the options in sequence. I did figure something out that gave me the record before the max, but for this problem I realy need the 1st through 4th, not the 4th through the 1st, since there could in theory be any number of options from 0 to whatever. The query I've built so far makes great use of subqueries and nexted subqueries. I recently discovered them and was intrigued, likely not that efficent yet. Anyway, I added one field with a number of nested subqueries to get the 2nd option, and it was soooooo slow.
Can anyone point me in the right direction for an sql subquery for sequencing in separate fields?
i.e. I have
Cust1, prod1, option1
Cust1, prod1, option2
Cust1, prod1, option3
Cust1, prod1, option4
Cust2, prod1
Cust3, prod1, option1
Cust3, prod1, option2
Cust4, prod1, option1
and I want:
Cust1, prod1, option1, option2, option3, option4
Cust2, prod1
Cust3, prod1, option1, option2
Cust4, prod1, option1
Thanks!