SQL Language (MOSC)

MOSC Banner

store with lowest load

edited Apr 17, 2012 2:21AM in SQL Language (MOSC) 4 commentsAnswered
We have a table called stores.
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?

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center