SQL Flashcards
What would the following command do?
SELECT * FROM movies
It would return all results from the table “movies”
What does WHERE do?
It filters queries based on criteria.
Example:
SELECT * FROM movies
WHERE imdb_rating > 8;
This would return every column from the table “movies” for any rows with a value greater than 8 in the “imdb_rating” column
What does AS do?
It determines what will be displayed as the column name for a query. It does not change the actual column name in the database.
Example:
SELECT imdb_rating AS ‘IMDB Rating’
FROM movies;
This would return the column “imdb_rating” but would display a title of “IMDB Rating”.
What command could you use to return the rows from the table “movies” where the “name” column is either “Se7en” or “Seven”?
SELECT *
FROM movies
WHERE name
LIKE ‘Se_en’;
The character “_” is wild.
What does the % operator do?
It filters query results to return any results which include the characters preceding, following, or between the percent symbol(s).
Example:
SELECT *
FROM movies
WHERE name
LIKE ____
Replacing the underlined values with
‘man%’ would return movies starting the string “man”
‘%man’ would return movies ending with the string ‘man’
‘%man%’ would return movies which contain the string ‘man’