store with lowest load
SQL> desc stores;
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEM NOT NULL VARCHAR2(100)
store NOT NULL VARCHAR2(10)
LOAD NUMBER(10)
Sample data:
ITEM1 store0 60
ITEM1 store1 59
ITEM2 store0 61
ITEM2 store1 48
ITEM2 store2 48
When a user order ITEM1, for example, we need to find the store with the lowest load that has ITEM1.
This is what I wrote
select store from (select store from stores where Item='ITEM1' order by Load) where ROWNUM=1;
Is there a more efficient way to write the above query?