Queries Flashcards
What is a core purpose of SQL?
To retrieve information stored in a database.
What is retrieving information stored in a database usually referred to as?
Querying
What type of statement would you use to only query data from two columns?
SELECT column1, column2
FROM table_name;
(SELECT statement)
What keyword lets you rename a column or table using an alias?
AS
Where must the new name in the AS keyword be placed in between?
Single quotes
’ ‘
What would be used to find the distinct values of a particular column?
DISTINCT
What does DISTINCT do?
Returns unique values in the output.
What does DISTINCT filter out?
All duplicate values in the specified columns.
Where does DISTINCT go in the SQL structure?
After the SELECT clause before the column name
SELECT DISTINCT ____
FROM _____;
What clause can be used to restrict query results in order to obtain only the information wanted?
WHERE
What does this statement do?
SELECT *
FROM movies
WHERE imdb_rating > 8;
The WHERE clause filters the result set to only include rows where the following condition is true
imdb_rating is the column
the > is the greater than operator
imdb_rating > 8 is a condition and only the rows with a value greater than 8 in the imdb_rating column will be returned.
What comparison operators are used with WHERE clauses?
== (equal to)
!= (not equal to)
> (greater)
< (lesser)
>= (greater than or equal to)
<= (lesser than or equal to)
What are Comparison Operators?
Operators create a condition that can be evaluated as either true or false.
What special operator is used with the WHERE clause to search for a specific pattern in a column?
LIKE
(LIKE I)
What is LIKE used for?
A useful operator to compare similar values.
What does this statement do?
SELECT *
FROM movies
WHERE name LIKE ‘Se_en’;
LIKE is a special operator used with the WHERE clause to search for a specific patter in a column
name LIKE ‘Se_en’ is a condition evaluating the name column for a specific pattern
Se_en represents a patter with a wildcard character
What wildcard character allows for individual character substitution without breaking the pattern?
_
LIKE searches for a specific what in a column?
pattern
What is a another wildcard character that can be used with LIKE that filters patterns?
%
The wildcard character % matches ______ or _________ in a pattern?
zero
missing letters