SQL - Queries Flashcards
_______is the clause we use every time we want to query information from a database.
SELECT
SELECT column1, column2
FROM table_name;
_______renames a column or table.
AS
SELECT name AS ‘Titles’
FROM movies;
_______ return unique values.
DISTINCT
SELECT DISTINCT tools
FROM inventory;
_______is a popular command that lets you filter the results of the query based on conditions that you specify.
WHERE
SELECT *
FROM movies
WHERE imdb_rating > 8;
_______and _______are special operators.
LIKE, BETWEEN
SELECT *
FROM movies
WHERE name LIKE ‘A%’;
SELECT *
FROM movies
WHERE year BETWEEN 1990 AND 1999;
_______ and _______ combines multiple conditions.
AND, OR
SELECT *
FROM movies
WHERE year BETWEEN 1990 AND 1999
AND genre = ‘romance’;
SELECT *
FROM movies
WHERE year > 2014
OR genre = ‘action’;
_______ sorts the result.
ORDER BY
SELECT *
FROM movies
ORDER BY name;
_______ specifies the maximum number of rows that the query will return.
LIMIT
SELECT *
FROM movies
LIMIT 10;
_______ creates different outputs
CASE
SELECT name,
CASE
WHEN imdb_rating > 8 THEN ‘Fantastic’
WHEN imdb_rating > 6 THEN ‘Poorly Received’
ELSE ‘Avoid at All Costs’
END
FROM movies;
Find the error in this code:
SELECT name,
CASE
WHEN imdb_rating > 8 THEN ‘Oscar’
WHEN imdb_rating > 7 THEN ‘Good’
WHEN imdb_rating > 6 THEN ‘Fair’
FROM movies;
Missing END statement.
IS NULL condition returns true if the field has no value. T/F?
T
How would you query all the unique genres from the ‘books’ table?
SELECT DISTINCT genres
FROM books;
What is LIKE?
A special operator that can be used with the WHERE clause to search for a pattern.
What does the wildcard character % in the following SQL statement do?
SELECT *
FROM sports
WHERE name LIKE ‘%ball’;
It matches all sports that end with ‘ball’.
What is the correct syntax to query both the name and date columns from the database?
SELECT __________
FROM album;
name, date