Join Clause Flashcards

2
Q

What does the JOIN clause do in SQL?

A

It combines rows from two or more tables based on related columns.

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

What is an INNER JOIN?

A

It returns only the rows where there is a match in both joined tables.

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

What is the syntax for INNER JOIN?

A

SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;

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

What is a LEFT JOIN?

A

It returns all rows from the left table, and matched rows from the right table; unmatched rows from the right table are filled with NULL.

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

What is the syntax for LEFT JOIN?

A

SELECT columns FROM left_table LEFT JOIN right_table ON left_table.column = right_table.column;

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

What is a RIGHT JOIN?

A

It returns all rows from the right table, and matched rows from the left table; unmatched rows from the left table are filled with NULL.

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

What is the syntax for RIGHT JOIN?

A

SELECT columns FROM left_table RIGHT JOIN right_table ON left_table.column = right_table.column;

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

Which JOIN returns only rows with matches in both tables?

A

INNER JOIN.

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

Which JOIN returns all rows from the left table?

A

LEFT JOIN.

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

Which JOIN returns all rows from the right table?

A

RIGHT JOIN.

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

If you want to show all customers and their orders, including customers with no orders, which JOIN do you use?

A

LEFT JOIN.

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

If you want to show only customers who have placed orders, which JOIN should you use?

A

INNER JOIN.

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

If you want to display all orders, even if they are not linked to a customer, which JOIN do you use?

A

RIGHT JOIN (assuming orders table is the right table).

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

Spot the mistake: ‘SELECT * FROM orders INNER JOIN customers orders.customer_id = customers.id;’

A

Missing ON keyword. Correct syntax: ON orders.customer_id = customers.id;

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

Spot the mistake: ‘RIGHT JOIN SELECT * FROM table1 table2 ON condition;’

A

Incorrect syntax. Correct: SELECT * FROM table1 RIGHT JOIN table2 ON condition;

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

What is the first step in a JOIN operation?

A

Form the Cartesian product of the two tables.

18
Q

What happens after the Cartesian product is formed in an INNER JOIN?

A

Filter the rows where the specified columns match.

19
Q

What happens to unmatched rows in a LEFT JOIN?

A

They are included, with NULL values for columns from the right table.

20
Q

What happens to unmatched rows in a RIGHT JOIN?

A

They are included, with NULL values for columns from the left table.

21
Q

If a LEFT JOIN is used and there are no matches in the right table, what is returned?

A

Rows from the left table with NULLs in the right table columns.

22
Q

If you mistakenly use INNER JOIN instead of LEFT JOIN, what data might you lose?

A

Records from the left table that have no matching row in the right table.

23
Q

Explain in your own words the difference between INNER JOIN and LEFT JOIN.

A

INNER JOIN returns only matching rows from both tables, while LEFT JOIN returns all rows from the left table and fills NULLs for unmatched right table rows.

24
Q

Describe a situation where you would prefer LEFT JOIN over INNER JOIN.

A

When you want to include all records from the left table, even if they have no matches in the right table.

25
Q

What is the difference between LEFT JOIN and RIGHT JOIN?

A

LEFT JOIN includes all rows from the left table, RIGHT JOIN includes all rows from the right table, with NULLs for unmatched rows from the opposite table.