Week 4 Flashcards

(35 cards)

1
Q

What is a subquery?

A

a query that is part of another query

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

What is a nested query?

A

a query that has an embedded subquery

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

What can a subquery be?

A

it can be a nested query itself!

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

What clauses can a subquery occur in?

A

SELECT, FROM, and WHERE (often appear here)

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

What is a good rule of thumb about nested queries?

A

AVOID THEM

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

What do we get when we use a subquery in a SELECT clause?

A

a single value

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

What do we get when we use a subquery in the FROM clause?

A

a relation

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

What do we get when we use a subquery in the WHERE or HAVING clause?

A

a single value to be compared with another value

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

Why are nested queries inefficient?

A

they run separately for each row which makes it slow for large datasets

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

What is subquery unnesting?

A

transforming a nested query into a single, flat query

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

How does unnesting work?

A

SQL rewrites the query to merge the subquery with the main query

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

What are quanitifiers?

A

they answer how many rows satisfy a condition

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

What is an existential quanitifier ask?

A

Does at least one row meet the condition?

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

What is an universal quantifier ask?

A

Do all rows meet the condition?

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

What are some key words that signify an existential quantifier?

A

“there exists”, “there is at least one”, or “for some”

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

What do we use for existential quanitifiers?

A

EXISTS, IN, NOT IN

17
Q

What do join queries do?

A

essentially evaluate the presence of existential quantifiers

18
Q

Existential quantifiers are ____________!

A

straightforward

19
Q

Universal quantifiers pose a ___________.

20
Q

What are some key words that signify universal quantifiers?

A

“given any”, “for all”, “for every”

21
Q

What do we use for universal quantifiers?

A

=, ≠, <=, =>

22
Q

What does it mean for a query to be monotone?

A

whenever we add tuples to one or more input tables, the answer to the query will not lose any output tuple

23
Q

What is the monotone queries theorem?

A

if Q is a SELECT-FROM-WHERE query that does not have subqueries, and no aggregates, then it is monotone

24
Q

If a query is monotonic, what does it imply?

A

that a nested query can be unnested and vice-versa

25
What kind of queries are non-monotone?
ones that contain universal quantifiers or negation and aggregates
26
What are the different set operations in SQL?
union, intersection, and differences
27
What are compound queries?
queries that contain set operators
28
What does a UNION operator do?
returns results from both queries after eliminating duplications
29
How do we use UNION?
in between two select statements
30
What is a condition we have to satisfy to use UNION?
number of columns and datatype must be same in both of the tables
31
What does UNION ALL do?
returns results from both queries including all duplications
32
What does INTERSECT do?
returns rows that are common to both queries
33
What does the MINUS operator do?
returns rows in the first query that are not present in the second query
34
Where can we use the MINUS operator?
in Oracle
35
Where can we use the EXCEPT operator?
SQL Server, PostgreSQL, SQLite