W3. SQL Inner Join Flashcards

1
Q

Q: What does the INNER JOIN keyword do?

A

A: It selects records with matching values in both tables.

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

Q: Write a query to join Products and Categories on CategoryID to select ProductID, ProductName, and CategoryName.

A

SELECT ProductID, ProductName, CategoryName
FROM Products
INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID;

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

Q: What happens to records without a match in an INNER JOIN?

A

A: They are not returned in the result.

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

Q: What is the syntax for using INNER JOIN?

A

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

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

Q: Why is it good practice to specify table names when using JOIN?

A

A: To avoid ambiguity, especially when columns with the same name exist in both tables.

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

Q: Write a query that specifies table names to join Products and Categories on CategoryID.

A

SELECT Products.ProductID, Products.ProductName, Categories.CategoryName
FROM Products
INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID;

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

Q: Are JOIN and INNER JOIN equivalent?

A

A: Yes, INNER JOIN is the default, so JOIN without INNER has the same effect.

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

Q: Write an example query using JOIN (without INNER) to join Products and Categories.

A

SELECT Products.ProductID, Products.ProductName, Categories.CategoryName
FROM Products
JOIN Categories ON Products.CategoryID = Categories.CategoryID;

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

Q: Can you JOIN more than two tables? If yes, how?

A

A: Yes, by joining additional tables in sequence using INNER JOIN with relevant keys.

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

Q: Write a query to join Orders, Customers, and Shippers to select OrderID, CustomerName, and ShipperName.

A

SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName
FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);

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