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 booksExplore Datasets
Use the books table to explore the data and practice your skills!
- Select only the
titlecolumn. - Alias the
titlecolumn asbook_title. - Select the distinct author names from the
authorcolumn. - Select all records from the table and limit your results to 10.
SELECT title
FROM booksSELECT title AS book_title
FROM booksSELECT DISTINCT author
FROM books
LIMIT 10Intermediate 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.