Queries Flashcards

1
Q

What is a core purpose of SQL?

A

To retrieve information stored in a database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is retrieving information stored in a database usually referred to as?

A

Querying

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of statement would you use to only query data from two columns?

A

SELECT column1, column2
FROM table_name;

(SELECT statement)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What keyword lets you rename a column or table using an alias?

A

AS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Where must the new name in the AS keyword be placed in between?

A

Single quotes

’ ‘

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What would be used to find the distinct values of a particular column?

A

DISTINCT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does DISTINCT do?

A

Returns unique values in the output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does DISTINCT filter out?

A

All duplicate values in the specified columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Where does DISTINCT go in the SQL structure?

A

After the SELECT clause before the column name

SELECT DISTINCT ____
FROM _____;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What clause can be used to restrict query results in order to obtain only the information wanted?

A

WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does this statement do?

SELECT *
FROM movies
WHERE imdb_rating > 8;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What comparison operators are used with WHERE clauses?

A

== (equal to)
!= (not equal to)
> (greater)
< (lesser)
>= (greater than or equal to)
<= (lesser than or equal to)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Comparison Operators?

A

Operators create a condition that can be evaluated as either true or false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What special operator is used with the WHERE clause to search for a specific pattern in a column?

A

LIKE

(LIKE I)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is LIKE used for?

A

A useful operator to compare similar values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does this statement do?

SELECT *
FROM movies
WHERE name LIKE ‘Se_en’;

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What wildcard character allows for individual character substitution without breaking the pattern?

A

_

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

LIKE searches for a specific what in a column?

A

pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a another wildcard character that can be used with LIKE that filters patterns?

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

The wildcard character % matches ______ or _________ in a pattern?

A

zero
missing letters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does this statement do?

SELECT *
FROM movies
WHERE name LIKE ‘A%’;

A

‘A%’ matches all movies with names that begin with the letter ‘A’.

22
Q

What does this statement do?

SELECT *
FROM movies
WHERE name LIKE ‘%a’;

A

‘%a’ matches all movies that end with a ‘a’.

23
Q

What does this statement do?

SELECT *
FROM movies
WHERE name LIKE ‘%man%’;

A

Any movie that contains the word ‘man’ in its name will be returned in the result.

24
Q

True or False: LIKE is not case sensitive.

25
What are unknown values indicated by?
NULL
26
NULL values can not be tested with comparison operators = and !=. What operators are used as a replacement?
IS NULL IS NOT NULL
27
What clause is the BETWEEN operator used in?
WHERE
28
What does the BETWEEN operator do?
Filters the result set within a certain range.
29
How many values does the BETWEEN operator accept?
Two
30
What kind of data types are acceptable values for a BETWEEN operator?
Numbers Text Dates
31
When the values are text, BETWEEN filers the result set for within what type of range?
Alphabetical
32
What would be filtered out from this statement? SELECT * FROM movies WHERE name BETWEEN 'A' AND 'J';
Filters the result set to only include movies with the names that begin with the letter 'A' up to, but not including ones that begin with the letter 'J'.
33
What would be filtered out from this statement? SELECT * FROM movies WHERE year BETWEEN 1990 AND 1999;
Filters the result set to only include movies with the years from 1990 up to and including 1999.
34
What operator is used with the WHERE clause to combine multiple conditions?
AND
35
Why would the AND operator be added in a WHERE clause?
To make the result set more specific and useful.
36
What does this statement do? SELECT * FROM movies WHERE year BETWEEN 1990 AND 1999 AND genre = 'romance';
year BETWEEN 1990 AND 1999 is the 1st condition genre = 'romance' is the 2nd condition AND combines the two conditions
37
True or False: With the AND operator, both conditions must be true for the row to be included in the result.
True
38
Which operator in the WHERE clause displays a row if any condition is true?
OR
39
What clause lists data in the result set in a particular order?
ORDER BY
40
Which two ways can the results be sorted using ORDER BY?
Alphabetically Numerically
41
What does this statement do? SELECT * FROM movies ORDER BY name;
ORDER BY is a clause that indicates you want to sort the result set by a particular column name is the specified column
42
Is this statement sorting data in a decreasing or increasing order? SELECT * FROM movies WHERE imdb_rating > 8 ORDER BY year DESC;
Decreasing
43
Which ORDER BY keyword sorts results from high to low or Z to A?
DESC
44
Which ORDER BY keyword sorts results from low to high or A to Z?
ASC
45
What is ASC and DESC in ORDER BY?
Keywords that stand for Ascending and Descending
46
What clause does ORDER BY always go after? (If this clause is present).
WHERE
47
What clause specifies a maximum number of rows the result will have?
LIMIT
48
Where does the LIMIT clause go on a query?
At the very end
49
What does this statement do? SELECT * FROM movies LIMIT 10;
LIMIT is a clause that lets you specify the maximum number of rows the result will have
50
What is an advantage of the LIMIT clause?
Saves space on screen Queries run faster
51
What type of statement allows for the creation of different outputs? (... consider it as an if-then logic)
CASE