Skip to content

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;

Spinner
DataFrameas
books
variable
-- Add your own queries here
SELECT * 
FROM books
Hidden output

Explore Datasets

Use the books table to explore the data and practice your skills!

  • Select only the title column.
  • Alias the title column as book_title.
  • Select the distinct author names from the author column.
  • Select all records from the table and limit your results to 10.
Spinner
DataFrameas
df
variable
SELECT title
FROM books
Hidden output
Spinner
DataFrameas
df1
variable
SELECT title AS book_title
FROM books
Hidden output
Spinner
DataFrameas
df2
variable
SELECT DISTINCT author
FROM books
LIMIT 10
Hidden output

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.

Spinner
DataFrameas
df4
variable
SELECT COUNT(*) AS total_records
FROM cinema.films;
Hidden output

DISTINCT

The SELECT DISTINCT statement is used to return only distinct (different) values.

Spinner
DataFrameas
df5
variable
SELECT DISTINCT title
FROM cinema.films
Hidden output
Spinner
DataFrameas
df6
variable
--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.