Data Query

For a complete syntax description of the SQL statements for data query, see Data Query in the SQL reference manual.

Below are just a few examples of key SQL statements for data query.

Prerequisites

You require the demo data for the SQL Tutorial.

Start the query tool SQL Studio as database administrator MONA with password RED and log on to the demo database instance DEMODB.

Example of a Data Query

SELECT zip, name, state
  FROM hotel.city
    WHERE name = 'Seattle'

This means:

?     Search (SELECT)

?     The zip, name, and state columns

?     From the city table of the hotel schema (FROM)

?     For the rows with the city name Seattle  (WHERE)

The form of a simple SELECT statement is therefore:

SELECT.....   
FROM.......   
WHERE......     

Result

ZIP

NAME

STATE

20005

Seattle

WA

20019

Seattle

WA

20037

Seattle

WA

Examples

Selecting, Arranging and Renaming Columns

Selecting and Arranging Rows

Conditions: Comparison, AND, OR, BETWEEN, IN

Searching for Character Strings: LIKE

Negative Conditions: NOT

Creating Groups: GROUP BY, HAVING

Arithmetic Operations

Functions

Set Functions

Date and Time Calculations

Converting Values

Changing Character Strings

Information About Character Strings

Subquery: Internal Queries

Joins: Information From Several Tables

Set Operations: UNION, INTERSECT, EXCEPT