Introduction to SQL
Here you can access the books
table used in the course.
Note: When using sample integrations such as those that contain course data, you have read-only access. You can run queries, but cannot make any changes such as adding, deleting, or modifying the data (e.g., creating tables, views, etc.).
STATEMENTS
SELECT
The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.
SYNTAX
SELECT column1, column2, ...
FROM table_name;
-- Add your own queries here
SELECT *
FROM books
Explore Datasets
Use the books
table to explore the data and practice your skills!
- Select only the
title
column. - Alias the
title
column asbook_title
. - Select the distinct author names from the
author
column. - Select all records from the table and limit your results to 10.
SELECT title
FROM books
SELECT title AS book_title
FROM books
SELECT DISTINCT author
FROM books
LIMIT 10
Intermediate SQL
Here you can access every table used in the course. To access each table, you will need to specify the cinema
schema in your queries (e.g., cinema.reviews
for the reviews
table.
Note: When using sample integrations such as those that contain course data, you have read-only access. You can run queries, but cannot make any changes such as adding, deleting, or modifying the data (e.g., creating tables, views, etc.).
COUNT
The COUNT() function returns the number of rows that matches a specified criterion.
SELECT COUNT(*) AS total_records
FROM cinema.films;
DISTINCT
The SELECT DISTINCT statement is used to return only distinct (different) values.
SELECT DISTINCT title
FROM cinema.films
--COUNT and DISTINCT combined.
--First remove duplicates using DISTINCT then use COUNT to count unique values.
SELECT COUNT(DISTINCT country) AS unique_countries
FROM cinema.films;
WHERE
The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition.