0% found this document useful (0 votes)
10 views

Basics of SQL SELECT Statement

Uploaded by

zanhezy89
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Basics of SQL SELECT Statement

Uploaded by

zanhezy89
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Basics of SQL SELECT Statement

SELECT column1, column2, ...


FROM table_name
WHERE condition
;

What do the keywords / clauses of a SQL statement shown above do?

● 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.

Why is there a semicolon after the SQL statements?

● 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

Task A: Example exercises on SELECT


statement
1. In this example, suppose we want to retrieve details of all the films from the
"FilmLocations" table. The details of each film record should contain all the film
columns.
1. Problem:
Retrieve all records with all columns from the "FilmLocations" table.
2. Solution:
SELECT * FROM FilmLocations;

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;

Task B: Practice exercises on SELECT


statement
1. Retrieve the fun facts and filming locations of all films.
2. Retrieve the names of all films released in the 20th century and before (release
years before 2000 including 2000) that, along with filming locations and release
years.
3. Retrieve the names, production company names, filming locations, and release
years of the films which are not written by James Cameron.

You might also like