Home arrow Oracle arrow Retrieve Data with the Select Statement

Retrieve Data with the Select Statement

Working with databases means retrieving data from tables. This is usually done with the SELECT statement. This nine-part article series will teach you all about this workhouse of the coding world. It is excerpted from chapter three of the book Murach's Oracle SQL and PL/SQL, written by Joel Murach (Murach Publishing; ISBN: 9781890774509).

  1. Retrieve Data with the Select Statement
  2. SELECT statement examples
By: Murach Publishing
Rating: starstarstarstarstar / 0
June 30, 2011

print this article



In this chapter, you’ll learn how to code SELECT statements that retrieve data from a single table. You should realize, though, that the skills covered here are the essential ones that apply to any SELECT statement, no matter how many tables it operates on and no matter how complex the retrieval. So you’ll want to have a good understanding of the material in this chapter before you go on to the chapters that follow.

An introduction to the SELECT statement

To help you learn to code the SELECT statement, this chapter starts by presenting its basic syntax. Next, it presents several examples that will give you an idea of what you can do with this statement. Then, the rest of this chapter will teach you the details of coding this statement.

The basic syntax of the SELECT statement

Figure 3-1 presents the basic syntax of the SELECT statement. The syntax summary at the top of this figure uses some conventions that are used throughout this book. First, capitalized words are called keywords, and you must spell them exactly as shown, though you can use whatever capitalization you prefer. For example, the following are equivalent: “SELECT”, “Select”, “select” and “sELeCt”. Second, you must provide replacements for words in lowercase. For example, you must enter a list of columns in place of select_list, and you must enter a table name in place of table_source.

Beyond that, you can choose between the items in a syntax summary that are separated by pipes (|) and enclosed in braces ({ }) or brackets ([]). And you can omit items enclosed in brackets. If you have a choice between two or more optional items, the default item is underlined. And if an element can be coded multiple times in a statement, it’s followed by an ellipsis (…). You’ll see examples of pipes, braces, default values, and ellipses in syntax summaries later in this chapter. For now, compare the syntax in this figure with the coding examples in figure 3-2 to see how the two are related.

The syntax summary in this figure has been simplified so that you can focus on the four main clauses of the SELECT statement: the SELECT clause, the FROM clause, the WHERE clause, and the ORDER BY clause. Most of the SELECT statements you code will contain all four clauses. However, only the SELECT and FROM clauses are required.

The SELECT clause is always the first clause in a SELECT statement. It identifies the columns you want to include in the result set. These columns are retrieved from the base tables named in the FROM clause. Since this chapter focuses on retrieving data from a single table, the FROM clauses in all of the statements in this chapter name a single base table. In the next chapter, though, you’ll learn how to retrieve data from two or more tables. And as you progress through this book, you’ll learn how to select data from other sources such as views and expressions.

The WHERE and ORDER BY clauses are optional. The ORDER BY clause determines how the rows in the result set are to be sorted, and the WHERE clause determines which rows in the base table are to be included in the result set. The WHERE clause specifies a search condition that’s used to filter the rows in the base table. This search condition can consist of one or more Boolean expressions, or predicates. A Boolean expression is an expression that evaluates

The simplified syntax of the SELECT statement

  SELECT select_list
  FROM table_source
  [WHERE search_condition]
  [ORDER BY order_by_list]

The four clauses of the SELECT statement  




Describes the columns that will be included in the result set.


Names the table from which the query will retrieve the data.


Specifies the conditions that must be met for a row to be included in the result set. This clause is optional.


Specifies how the rows in the result set will be sorted. This clause is optional.


  1. You use the basic SELECT statement shown above to retrieve the columns specified in the SELECT clause from the base table specified in the FROM clause and store them in a result set.
  2. The WHERE clause is used to filter the rows in the base table so that only those rows that match the search condition are included in the result set. If you omit the WHERE clause, all of the rows in the base table are included. 
  3. The search condition of a WHERE clause consists of one or more Boolean expressions, or predicates, that result in a value of True, False, or Unknown. If the combination of all the expressions is True, the row being tested is included in the result set. Otherwise, it’s not. 
  4. If you include the ORDER BY clause, the rows in the result set are sorted in the specified sequence. Otherwise, the sequence of the rows is not guaranteed by Oracle.


  • The syntax shown above does not include all of the clauses of the SELECT statement. You’ll learn about the other clauses later in this book.

--------------------------------------------Figure 3-1   The basic syntax of the SELECT statement

to True or False. When the search condition evaluates to True, the row is included in the result set.

In this book, we won’t use the terms “Boolean expression” or “predicate” because they don’t clearly describe the content of the WHERE clause. Instead, we’ll just use the term “search condition” to refer to an expression that evaluates to True or False.

>>> More Oracle Articles          >>> More By Murach Publishing

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: