GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Oracle
Go To First  |  Previous Question  |  Next Question 
 Oracle  |  Question 15 of 244    Print  
what is the difference between ALL and ANY in ORACLE?
can any one explain with example?

  
Total Answers and Comments: 4 Last Update: June 28, 2009     Asked by: abhimanu.singh 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Nikhil_4_Oracle
 

DEAR ALL,

ANY or SOME : Compares a value to each value in a list or retuned by a query. Must be

preceded by =,!=,>,<,<=,=> Evalutes FALSE when query returns no rows.



select empno,ename,sal from emp where sal = any(1500,3000);


EMPNO ENAME    SAL

------- ---------- ----------

7499 ALLEN 1600

7566 JONES 2975

7839 KING 5000

7902 FORD 3000


so ,optimizer take above query as ,

--select empno,ename,sal from emp where sal>1500 or sal>3000;


ALL : Compares a value to every value in a list or return by a query .Must be preceded by

=,!=,>,<,=>,<=. Evalutes to TRUE if the query returns no rows.


select empno,ename,sal from emp where sal > ALL (1600,3000);


EMPNO ENAME SAL

---------- ---------- ----------

7839 KING 5000


-- in other words optimizer take this query as ,

--select empno,ename,sal from emp where sal 1600 AND sal>3000;



Regards,

Nikhil






Above answer was rated as good by the following members:
mittu.jangid
April 19, 2006 16:56:42   #1  
vijay Jaiswal        

RE: what is the difference between ALL and ANY in ORAC...

ANY
The If any value from outcome of subquery is macthed then desired output will be retrived.It checks with lowest value .

ALL
Itwill check for greatest value from outcome of subquery


 
Is this answer useful? Yes | No
March 15, 2007 03:34:51   #2  
Nikhil_4_Oracle        

RE: what is the difference between ALL and ANY in ORAC...

DEAR ALL

ANY or SOME : Compares a value to each value in a list or retuned by a query. Must be

preceded by ! > < < > Evalutes FALSE when query returns no rows.



select empno ename sal from emp where sal any(1500 3000);


EMPNO ENAME SAL

------- ---------- ----------

7499 ALLEN 1600

7566 JONES 2975

7839 KING 5000

7902 FORD 3000


so optimizer take above query as

--select empno ename sal from emp where sal>1500 or sal>3000;


ALL : Compares a value to every value in a list or return by a query .Must be preceded by

! > < > < . Evalutes to TRUE if the query returns no rows.


select empno ename sal from emp where sal > ALL (1600 3000);


EMPNO ENAME SAL

---------- ---------- ----------

7839 KING 5000


-- in other words optimizer take this query as

--select empno ename sal from emp where sal 1600 AND sal>3000;



Regards

Nikhil





 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
November 14, 2007 07:33:19   #3  
rajakumar_na Member Since: November 2007   Contribution: 26    

RE: what is the difference between ALL and ANY in ORAC...
ANY and ALL are Multiple row operators.
<ANY - Less than the Maximum
>ANY - Greater than the Minimum
<ALL - Less than the Minimum
>ALL - Greater than the maximum

 
Is this answer useful? Yes | No
June 26, 2009 00:14:24   #4  
sure_prince Member Since: June 2009   Contribution: 5    

RE: what is the difference between ALL and ANY in ORACLE?can any one explain with example?
IN->Equal to Any One in the List.

ANY->Compares Value to Each Value Returned by the Sub Query.

ALL->Compares Value To Every Value Returned by the Sub Query.

For Example:

IN:
(Q):Display the Details of all the Employees Whose Salaries are Matching with Least Investments of Departments?

(A):
SQL>Select Ename Sal Deptno from Emp Where
Sal IN(Select Min(Sal) From Emp Group By Deptno);

ANY:

<ANY:->Meaans Less Than The Maximum Value in the List.

(Q):Get The Details of All Employees Who are Earning Less Than The Highest Earning Employee Controling Other Emp?

(A):
SQL>Select Empno Ename Job Sl From Emp
Where Sal <Any(Select Distinct MGR From Emp));

>ANY:->Meaans More Than The Minimum Value in the List.

(Q):Get The Details Of All Emps Who are Earning more than the least paid of Department 10?

(A):
SQL>Select Empno Ename Job Sal From Emp
Where Sal>Any(Select Min(Sal) From Emp Where Deptno 10);

ANY:->It's Equivalent to In Operator.

Note: 'Some' is also used insted of ANY.


ALL

<ALL:->Means Less Than The Minimum Value in the List.

(Q):Get The Details Of All Emps Who are Earning Less than the
Avg Investment of Department 10?

(A):
SQL>Select Empno Ename Job Sal From Emp
Where Sal<All(Select Avg(Sal) From Emp Where Deptno 10);

>ALL:->Means More Than The Maximum Value in the List.

(Q):Get The Details Of All Emps Who are Earning More than the
Avg Investment of Department 10?

(A):
SQL>Select Empno Ename Job Sal From Emp
Where Sal>All(Select Avg(Sal) From Emp Where Deptno 10);



Thank you
Any Mistakes please Inform to me...

-Suresh





 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape