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.

A

True

25
Q

What are unknown values indicated by?

A

NULL

26
Q

NULL values can not be tested with comparison operators = and !=. What operators are used as a replacement?

A

IS NULL
IS NOT NULL

27
Q

What clause is the BETWEEN operator used in?

A

WHERE

28
Q

What does the BETWEEN operator do?

A

Filters the result set within a certain range.

29
Q

How many values does the BETWEEN operator accept?

A

Two

30
Q

What kind of data types are acceptable values for a BETWEEN operator?

A

Numbers
Text
Dates

31
Q

When the values are text, BETWEEN filers the result set for within what type of range?

A

Alphabetical

32
Q

What would be filtered out from this statement?

SELECT *
FROM movies
WHERE name BETWEEN ‘A’ AND ‘J’;

A

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
Q

What would be filtered out from this statement?

SELECT *
FROM movies
WHERE year BETWEEN 1990 AND 1999;

A

Filters the result set to only include movies with the years from 1990 up to and including 1999.

34
Q

What operator is used with the WHERE clause to combine multiple conditions?

A

AND

35
Q

Why would the AND operator be added in a WHERE clause?

A

To make the result set more specific and useful.

36
Q

What does this statement do?

SELECT *
FROM movies
WHERE year BETWEEN 1990 AND 1999
AND genre = ‘romance’;

A

year BETWEEN 1990 AND 1999 is the 1st condition
genre = ‘romance’ is the 2nd condition
AND combines the two conditions

37
Q

True or False: With the AND operator, both conditions must be true for the row to be included in the result.

A

True

38
Q

Which operator in the WHERE clause displays a row if any condition is true?

A

OR

39
Q

What clause lists data in the result set in a particular order?

A

ORDER BY

40
Q

Which two ways can the results be sorted using ORDER BY?

A

Alphabetically
Numerically

41
Q

What does this statement do?

SELECT *
FROM movies
ORDER BY name;

A

ORDER BY is a clause that indicates you want to sort the result set by a particular column
name is the specified column

42
Q

Is this statement sorting data in a decreasing or increasing order?

SELECT *
FROM movies
WHERE imdb_rating > 8
ORDER BY year DESC;

A

Decreasing

43
Q

Which ORDER BY keyword sorts results from high to low or Z to A?

A

DESC

44
Q

Which ORDER BY keyword sorts results from low to high or A to Z?

A

ASC

45
Q

What is ASC and DESC in ORDER BY?

A

Keywords that stand for Ascending and Descending

46
Q

What clause does ORDER BY always go after? (If this clause is present).

A

WHERE

47
Q

What clause specifies a maximum number of rows the result will have?

A

LIMIT

48
Q

Where does the LIMIT clause go on a query?

A

At the very end

49
Q

What does this statement do?

SELECT *
FROM movies
LIMIT 10;

A

LIMIT is a clause that lets you specify the maximum number of rows the result will have

50
Q

What is an advantage of the LIMIT clause?

A

Saves space on screen
Queries run faster

51
Q

What type of statement allows for the creation of different outputs? (… consider it as an if-then logic)

A

CASE