Wednesday, March 3, 2010

ANY SOME AND ALL in Oracle

ANY SOME AND ALL


ANY or SOME:

Compares a value to each value in a list or returned by a query. Must be preceded by =, !=, >, <, <=, >=. Evaluates to FALSE if the query returns no rows.

Using Any

select ename, sal from emp where sal > any (1600, 2999);
Alternatively

select ename, sal from emp where sal > 1600 or sal > 2999;

ALL:

Compares a value to every value in a list or returned by a query. Must be preceded by =, !=, >, <, <=, >=. Evaluates to TRUE if the query returns no rows.

Using All

select ename, sal from emp where sal > all (1600, 2999);

Alternatively

select ename, sal from emp where sal > 1600 and sal > 2999;

1 comment:

  1. Thank you so much for clearing out all the confusions that were in my mind about all these three clauses. Each of them is so neatly explained and the usage of all of them is more cleared when I executed the queries that you have shared.
    sap upgrade planning

    ReplyDelete