Subqueries Flashcards

1
Q

Subquery

A

A subquery is a SQL query nested inside a larger query

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

SELECT lastName, firstName
FROM employees
WHERE officeCode IN
(SELECT officeCode
FROM offices
WHERE country = ‘USA’);

Is the “SELECT lastName, firstName” query the outer or inner query?

A

The outer query

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

SELECT lastName, firstName
FROM employees
WHERE officeCode IN
(SELECT officeCode
FROM offices
WHERE country = ‘USA’);

Is the “SELECT officeCode” query within the parenthesis the outer or inner query?

A

The inner query

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

What do we need to add to the subquery of a FROM clause in order for it to work?

A

An AS keyword

This will give the temporary table created by the subquery a name that the outer query can use to pull the information from.

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

When you have a query inside of another query, the term “subquery” refers to which query?

A

The inner query

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

Correlated Subquery

A

Is a subquery that contains a reference to a table that also appears in the outer query.

The correlation comes from the fact that the subquery uses information from the outer query and the subquery executes once for every row in the outer query.

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