Oracle SQL - Introduction Data Retrieval

Introduction

The only SQL command used to query database data is SELECT.

This command acts at the table level, and always produces a set as its result.

If a certain query returns exactly one row, or no rows at all, the result is still a set: a table with one row or the empty table, respectively.

The SELECT command has six main components, which implement all SQL retrieval.

  • The SELECT and FROM components are mandatory.
  • The remaining components (WHERE, GROUP BY, HAVING, and ORDER BY) are optional.

The following table lists a high-level description of the roles of these six components of the SELECT command.

Component Description
FROM table(s) is (are) needed for retrieval
WHERE condition to filter the rows?
GROUP BY How should the rows be grouped/aggregated?
HAVINGthe condition to filter the aggregated groups?
SELECTWhich columns do you want to see in the result?
ORDER BY In which order do you want to see the resulting rows?