Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB   


 

 

 


 

 

 
 

Oracle SQL: Basic SQL subqueries


Oracle Tips by Burleson Consulting

 

When we see a SQL statement that specifies a subquery, we first need to carefully check the where clause and determine if the subquery is a noncorrelated subquery or a correlated subquery. A correlated subquery is a query whereby the key in the subquery is correlated (using the = operator) with a column that is selected in the outer query.

On the other hand, a noncorrelated subquery is a query where the subquery executes independently of the outer query, passing a result set to the outer query at the end of its execution. Noncorrelated subqueries are commonly seen when using the IN, NOT IN, EXISTS, and NOT EXISTS SQL clauses.

In a basic subquery, an SQL statement is embedded inside the WHERE clause of the query. In this example, we locate all authors who have not yet published a book.

select
author_last_name
from
author
where
author_key not in
(select author_key from book_author);

This type of query is called a non-correlated subquery because the subquery does not make any references to the outside query. To see how this works, copy this code from this screen and run it against your pubs database. You should get the following output:

AUTHOR_LAST_NAME
----------------------------------------
clark
mee

In this example, we select all authors who have not yet published their first book. Internally, this query reads all author_key values from the book_author table and then compares this result set with the author_key value in the author table. The savvy Oracle SQL tuner is always on the lookout for both correlated and noncorrelated subqueries for several reasons.

The foremost is to search for opportunities for replacing the subquery with a standard join, and the other is to examine the uniqueness of the indexes in the subquery to see if changing the index structure can change the table access method.

Note: Prior to Oracle10g there was a bug that caused a huge execution difference between EXISTS and IN.  Starting in 10g release 2 and beyond, Oracle \will automatically rewrite an IN subquery to use the EXISTS clause.

 

For a complete overview of Oracle SQL, see the book "Easy Oracle SQL".  It's only $9.95 and has a downloadable code depot:

http://www.rampant-books.com/book_2005_1_easy_sql.htm

Note: These exercises may use the pubsdb.sql script that can be downloaded at this link.


 

 

  
 

 
 
 
 
Oracle performance tuning software
 
 

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2012 

All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.