Basics of SQL SELECT Statement
Basics of SQL SELECT Statement
● FROM: Specifies from which table to get the data. The clause can include
optional JOIN subclauses to specify the rules for joining tables.
● [Optional Clause] WHERE : Specifies which rows to retrieve.
● Some database systems require a semicolon at the end of each SQL statement
for execution. It is a standard way to separate one SQL statement from another
which allows more than one SQL statement to be executed in the same call to
the server. So, it is good practice to use a semicolon at the end of each SQL
statement.
Database:
https://data.sfgov.org/Culture-and-Recreation/Film-
Locations-in-San-Francisco/yitu-d5am
2. In this example, now we want to retrieve selective details of all the film records. Let
us retrieve the names of all the films along with director names and writer names.
1. Problem:
Retrieve the names of all films with director names and writer names.
2. Solution:
SELECT Title, Director, Writer FROM FilmLocations;
3. In this example, we want to retrieve film names along with filming locations and
release years. But we also want to restrict the output resultset so that we can retrieve
only the film records released in 2001 and onwards (release years after 2001 including
2001).
1. Problem:
Retrieve the names of all films released in the 21st century and onwards
(release years after 2001 including 2001), along with filming locations and
release years.
2. Solution:
SELECT Title, ReleaseYear, Locations FROM FilmLocations WHERE
ReleaseYear>=2001;