GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL Plus
Go To First  |  Previous Question  |  Next Question 
 SQL Plus  |  Question 6 of 132    Print  
What is the sub-query

  
Total Answers and Comments: 9 Last Update: January 22, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Sailaja Pasupuleti
 

    A sub-query is a part of query.  Sub-queries are useful to find unknown value(s).

   Ex:  To find details of employees who are getting maximum salary.

         In this requirement, the maximum salary not mentioned.

Solution:    

To find maximum salary, 

          select max(sal) from emp;

For that maximum salary the employee details, 

          select * from emp where  sal = (select max(sal) from emp);

So, in the above query, "select max(sal) from emp"  is also a query but it returns a value (unknown or not given) and compares with "sal" column.  This query is called sub-query.



Above answer was rated as good by the following members:
premramana
March 22, 2005 17:58:26   #1  
nalini        

RE: What is the sub-query
subquery is inner query executes before the the main query.the result of the subquery used in main query
 
Is this answer useful? Yes | No
July 20, 2005 05:28:56   #2  
srinivas.T.T        

RE: What is the sub-query
Query with in Query is nothing but subquery. Subquery execute only once per table
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
September 09, 2005 12:01:15   #3  
prathima        

RE: What is the sub-query
a subquery is a SELECT statement that is written inside another SQL statement (which is often but does not have to be another SELECT). To distinguish the subquery (or inner query) from its enclosing query (or outer query) it must be enclosed within parentheses. Here is an example:

SELECT * FROM clients WHERE clno IN -- outer query
(SELECT clno FROM firms WHERE city 'leduc'); -- inner query


 
Is this answer useful? Yes | No
October 15, 2005 04:57:24   #4  
annathurai        

RE: What is the sub-query
sub-query nothing but Queries within the queries is called the sub -query.example:select empno empname frome employee where empno (select empno from empdetails)
 
Is this answer useful? Yes | No
December 03, 2005 22:26:01   #5  
Sailaja Pasupuleti        

RE: What is the sub-query

A sub-query is a part of query. Sub-queries are useful to find unknown value(s).

Ex: To find details of employees who are getting maximum salary.

In this requirement the maximum salary not mentioned.

Solution:

To find maximum salary

select max(sal) from emp;

For that maximum salary the employee details

select * from emp where sal (select max(sal) from emp);

So in the above query select max(sal) from emp is also a query but it returns a value (unknown or not given) and compares with sal column. This query is called sub-query.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 19, 2006 01:04:38   #6  
aseemnaithani Member Since: February 2006   Contribution: 10    

RE: What is the sub-query
Please can you tell me the difference between In and Exists predicates in the sun-query
 
Is this answer useful? Yes | No
August 28, 2006 17:14:34   #7  
shobana        

RE: What is the sub-query- In and Exists

In is used to find in a range of values.

Eg: select empno ename from employee where department in ( SALES ACCOUNTS FINANCE HR );

Records from every department are fetched. Checks department whether in SALES or in ACCOUNTS or in FINANCE or in HR.

Exists just checks for the condition and returns true or false.

Eg: select empno ename from employee where exists(sal>0);


 
Is this answer useful? Yes | No
October 24, 2006 23:42:38   #8  
thumatinagaraju Member Since: October 2006   Contribution: 26    

RE: What is the sub-query
simple reply nalini ..goodnagthumati_nagaraju@yahoo.co.in
 
Is this answer useful? Yes | No
January 22, 2007 00:30:35   #9  
kshsingh1 Member Since: November 2005   Contribution: 3    

RE: What is the sub-query
A query nested within another SQL statement is called a subquery.
 
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