Intermediate SQL - Selecting Data Flashcards

In this first chapter, you’ll learn how to query a films database and select the data needed to answer questions about the movies and actors. You'll also understand how SQL code is executed and formatted.

1
Q

What is a query?

A

a request for data from a database

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

What keyword/function would we use to count the number of records with a value in a field?

A

COUNT()

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

True/False - If we want to count more than one field, we do not need to use COUNT() multiple times.

A

False - need to use the COUNT() function on each field you want to count

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

What does this query do? COUNT(field_name)

A

counts values in a field

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

What query do we use to count the number of records in a table?

A

COUNT(*)

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

What operator will remove duplicates to return only unique values?

A

DISTINCT

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

What two keywords can be combined to count the unique values in a field

A

COUNT() with DISTINCT - in this example, DISTINCT is excluding duplicates of people with the same birthday before COUNT()

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

True/False - COUNT() does not include duplicates

A

False - COUNT() includes duplicates

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

True/False - DISTINCT excludes duplicates

A

True

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

Unlike many programming languages, SQL is not what?

A

not processed in its written order

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

What is the first keyword that gets executed in SQL?

A

FROM - if we want to grab a coat/field from a closet/table, we need to know which closet/table to get it from

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

What keyword will limit how many results we return?

A

LIMIT

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

Its good to know processing order for what two reasons?

A

1) debugging
2) aliasing

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

Aliases are declared in which statement?

A

SELECT statement

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

What are the 3 common errors found when debugging SQL?

A

1) misspelling
2) incorrect capitalization
3) incorrect or missing punctuation, especially commas

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

True/False - Formatting is required in SQL.

A

False - formatting is not required and the code will run fine without formatting but lack of formatting makes it difficult for others to read

17
Q

What are three reasons why you should end a query with a semicolon?

A

1) best practice
2) easier to translate between SQL flavors
3) indicates end of a query