Module 02b - Basic SQL - Part II/II Flashcards

1
Q

What are subqueries

A

When one SQL query is embedded in another SQL query

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

What is the syntax of a subquery in a DDL statement

A
SELECT	SUM (ExtendedPrice) AS Revenue
FROM ORDER_ITEM
WHERE SKU IN
	(SELECT   SKU
	FROM SKU_DATA
	WHERE Department = 'Water Sports');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to connect two or more tables

A

By joining “composite” rows from multiples tables as long as they have fields that can link the rows of one table with the rows in another table.

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

What’s the syntax to perform a junction between tables

A

SELECT Column1, Column2
FROM TABLE1, TABLE2
WHERE TABLE1.ColumnX = TABLE2.ColumnY
//admits AND or OR operators on WHERE clause

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

How the JOIN ON operator works?

A

By “derivating” a new table JOINING rows ON their attributes are common.

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

What’s is the syntax of JOIN ON

A

SELECT Column1, Column2
FROM TABLE1 JOIN TABLE2
ON TABLE1.ColumnX = TABLE2.ColumnY
WHERE ColumnWhatever > 1000000

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

How INNER JOIN works?

A

Returns all rows when there is at least one match in BOTH tables

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

How LEFT JOIN works?

A

Return all rows from the left table, and the matched rows from the right table

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

How RIGHT JOIN works?

A

Return all rows from the right table, and the matched rows from the left table

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

How FULL JOIN works?

A

Return all rows when there is a match in ONE of the tables

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

Recap

A

SELECT … FROM … WHERE …
Like
Build-in functions
GROUP BY: HAVING v.s. WHERE

Querying multiple tables: Sometimes, a join can be used as an alternative to a subquery, and a subquery can be used as an alternative to a join.

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