dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Enterprise
Expertise: Advanced
Aug 25, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


SubQueries in the FROM Clause of SELECT

When a SubQuery is used in a FROM clause instead of a Table name, Oracle executes the subquery and then uses the resulting rows as a view in the FROM clause. It's a very useful method for performing reports with various types of counts.

Consider the following classic query, which counts the number of awards accepted or rejected by employees. It does an outer join to take care of employees who might have only accepted or only rejected awards. This will give one row per employee in an emp_status table:

 select a.id, nvl(accepted, 0)  TotAccepted, 
nvl(rejected, 0) TotRejected, fname from emp_status a, (select count(*) accepted, id,
code , status from emp_status where code = 'AWARD' and status = 'A' group by id, code, status ) b , (select count(*) rejected, id,
code , status from emp_status where code = 'AWARD' and status = 'R' group by id, code, status) c , (select id, fname from employee) d where a. code = 'AWARD' and a.status in ('R', 'A') and a.id = b.id(+) and a.id = c.id(+) and a.id = d.id group by a.id, accepted, rejected, fname
Trupti Rajparia
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date