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.
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.
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 |
Selecting, Arranging and Renaming Columns
Conditions: Comparison, AND, OR, BETWEEN, IN
Searching for Character Strings: LIKE
Creating Groups: GROUP BY, HAVING
Information About Character Strings
Joins: Information From Several Tables
Set Operations: UNION, INTERSECT, EXCEPT