mainrotor
asked on
I have a question regarding a query in SQL Server 2008 R2
Dear Experts,
I have to write a query that returns the top SKU on each of my orders.
I have 3 order
ORDER1 has the following SKUs
ABC123
DEF456
ORDER2 has the following SKUs
DEF456
XYZ765
ZZZ656
ORDER3 has the following SKUs
EFG123
RRS697
XYZ765
XYZ999
I want my query to return the following result
ORDER # TOP SKU
ORDER1 ABC123
ORDER2 DEF456
ORDER3 EFG123
How can I do this? Thanks in advance,
mrotor
I have to write a query that returns the top SKU on each of my orders.
I have 3 order
ORDER1 has the following SKUs
ABC123
DEF456
ORDER2 has the following SKUs
DEF456
XYZ765
ZZZ656
ORDER3 has the following SKUs
EFG123
RRS697
XYZ765
XYZ999
I want my query to return the following result
ORDER # TOP SKU
ORDER1 ABC123
ORDER2 DEF456
ORDER3 EFG123
How can I do this? Thanks in advance,
mrotor
ASKER
Vitor,
I just need it to pick one. How can I do this? It doesn't really matter which one it picks, as long as it only picks one.
mrotor
I just need it to pick one. How can I do this? It doesn't really matter which one it picks, as long as it only picks one.
mrotor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And something like :
select 'ORDER1', min(SKU) from ORDER1
union
select 'ORDER2', min(SKU) from ORDER2
union
select 'ORDER3', min(SKU) from ORDER3
By the examples you gave I would say is alphabetic ascending order?