Call (800) 766-1884 for Oracle support & training
Free Oracle Tips


Oracle Consulting Support
Oracle Upgrades
Use New Oracle Features
Oracle Replication Support
Oracle Training
Remote Oracle DBA
System Documentation
Oracle Tips
Oracle Performance
 

Free Oracle Tips


 

HTML Text

BC Oracle tuning

Oracle training

Oracle support

Remote Oracle

 

 

   
  Oracle Tips by Burleson

Single Row Subquery

A single row subquery returns only one row.  It can be used with the equal comparison operators (=,<,>,<>, etc).  

SQL> select
  2    order_number
  3  from
  4    sales
  5  where quantity = (select
  6                      max(quantity)
  7                    from
  8                      sales);
ORDER_NUMBER
--------------------
O161 

Here, we get the order number for the order that contains the max quantity value.  The outer query can return multiply rows, but the subquery can only return one row.

SQL> select
  2    order_number
  3  from
  4    sales 
  5  where quantity > (select
  6                      avg(quantity)
  7                    from
  8                      sales); 
ORDER_NUMBER
--------------------
O118
O149
O157
O161
O167
O179
O183
O186
O189
O193
O196
O197
O198
O199
14 rows selected.

Here, we want the order numbers where the order quantity is above the average quantity in the sales table.  Notice that the subquery returns one and only one row that used in the filter.


The above book excerpt is from:

Easy Oracle SQL

Get Started Fast writing SQL Reports with SQL*Plus

ISBN 0-9727513-7-8

Col. John Garmany 

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

  
 

Oracle performance tuning software 
 
 
 
 

Oracle performance tuning book

 

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

 

   

Copyright © 1996 -  2014 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.