Link to home
Start Free TrialLog in
Avatar of mainrotor
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
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

How do we know which one is the top?
By the examples you gave I would say is alphabetic ascending order?
Avatar of mainrotor
mainrotor

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
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And something like :
select 'ORDER1', min(SKU) from ORDER1
union
select 'ORDER2', min(SKU) from ORDER2
union
select 'ORDER3', min(SKU) from ORDER3

Open in new window