Home arrow Oracle arrow Stepping through Sub-Queries in Oracle

Stepping through Sub-Queries in Oracle

This is the first article in a series concentrating on working with sub-queries in Oracle. Sub-queries really have tremendous depth. In this series I will show you several scenarios where they can be efficiently used to retrieve information from Oracle databases.

  1. Stepping through Sub-Queries in Oracle
  2. The simplest sub-query in Oracle
  3. A sub-query with aggregate functions (or group functions) in Oracle
  4. Designing sub-queries to deal with more than one table (or different tables)
  5. An example of a nested sub-query (or multi-level sub-query)
By: Jagadish Chatarji
Rating: starstarstarstarstar / 28
November 07, 2006

print this article



As this is the first in series, I will be concentrating on the following topics:

  • How to work with a “dual” table.
  • How to analyze and identify the steps needed to deal with a sub-query.
  • How to frame queries for each of the identified steps.
  • How to combine all the framed queries and design a single command to retrieve the final output.

A primer on the “dual” table in Oracle

This section mainly explains the “dual” table in Oracle.  I shall use this table in a creative manner wherever required in this article as well as upcoming articles.  If you are already familiar with the "dual” table, feel free to skip to the next section.

What is a “dual” table?  It is a simple table which is created/installed automatically during the installation of the Oracle database.  To understand it, let us consider the following SELECT statement:

SELECT 123 FROM dual;

The above statement simply returns 123.  Let us work with another statement:

SQL> SELECT 10,20,'Jagadish Chatarji',3400 FROM dual;

10    20    'JAGADISHCHATARJI' 3400                   

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

10    20    Jagadish Chatarji  3400                  

1 rows selected

This returns any constant values you provide as columns.  So “dual” is just a convenience table.  It is simply a one column and one row table that exists as part of SYS user.  You can use the DESC command to display the structure of a “dual” table as follows:

DESC dual;

The above statement returns the following output:










You can observe that there exists only one column named “dummy” in the "dual" table.  Similarly, you can even display all the rows in the "dual" table as follows:





1 rows selected

From the above, you can observe that there exists only one row with a dummy value of "x." 

You don't really need to use the “dual” table at all.  It is only used when you want to add/include any constant values in your queries.  You can even do calculations as follows:

SQL> SELECT 12 * 13 + 14 FROM dual;




1 rows selected

>>> More Oracle Articles          >>> More By Jagadish Chatarji

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Oracle Java Security Woes Continue
- Oracle's New IaaS Cloud Option: There's a Ca...
- Oracle Acquires Eloqua to Boost Cloud Presen...
- Choosing Innovation: Oracle Survey Insights
- Oracle Fixes Privilege Escalation Bug
- Oracle`s Communications Service Availability...
- Oracle Releases Exalytics, Taleo Plans
- Oracle Releases Communications Network Integ...
- Oracle Releases Communications Data Model 11...
- Oracle Releases PeopleSoft PeopleTools 8.52
- Oracle Integrates Cloudera Apache Distro, My...
- Oracle Releases MySQL 5.5.18
- Oracle Announces NoSQL Database Availability
- Sorting Database Columns With the SELECT Sta...
- Retrieving Table Data with the LIKE Operator

Developer Shed Affiliates


Dev Shed Tutorial Topics: