Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Understanding INNER JOIN | Core Join Types and Their Applications
SQL Joins in Depth

bookUnderstanding INNER JOIN

When you need to combine rows from two tables and only want to see the records where there is a match in both tables, you use an INNER JOIN. This join type is one of the most commonly used in SQL, especially when you want to analyze relationships between related data sets. For example, if you want a list of customers who have actually placed orders (excluding those who never ordered), INNER JOIN is the tool for the job. This is useful in many real-world scenarios, such as generating sales reports, finding active users, or matching transactions with their corresponding details.

123456789
SELECT customers.name AS customer_name, orders.amount AS order_amount FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;
copy

This query demonstrates how INNER JOIN works to combine information from the customers and orders tables. The query selects the name column from the customers table and the amount column from the orders table. The join condition is specified by the ON clause: customers.customer_id = orders.customer_id. This means that only those rows where a customer has a matching order (that is, the customer_id exists in both tables) will be included in the result. Customers who have not placed any orders—like Charlie Lee and Eve Adams in the sample data—will not appear in the output. Similarly, any order that is not linked to a valid customer would also be excluded, though in the provided data all orders reference existing customers.

1234567891011
SELECT orders.order_id, products.product_name FROM orders INNER JOIN order_products ON orders.order_id = order_products.order_id INNER JOIN products ON order_products.product_id = products.product_id;
copy

1. What does INNER JOIN return if there are no matching records in both tables?

2. Which clause specifies the columns used for joining two tables in an INNER JOIN?

3. Fill in the blanks for an INNER JOIN query joining customers and orders on customer_id.

question mark

What does INNER JOIN return if there are no matching records in both tables?

Select the correct answer

question mark

Which clause specifies the columns used for joining two tables in an INNER JOIN?

Select the correct answer

question-icon

Fill in the blanks for an INNER JOIN query joining customers and orders on customer_id.

SELECT customers.name, orders.order_date FROM customers orders customers.customer_id = orders.customer_id;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 1

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookUnderstanding INNER JOIN

Свайпніть щоб показати меню

When you need to combine rows from two tables and only want to see the records where there is a match in both tables, you use an INNER JOIN. This join type is one of the most commonly used in SQL, especially when you want to analyze relationships between related data sets. For example, if you want a list of customers who have actually placed orders (excluding those who never ordered), INNER JOIN is the tool for the job. This is useful in many real-world scenarios, such as generating sales reports, finding active users, or matching transactions with their corresponding details.

123456789
SELECT customers.name AS customer_name, orders.amount AS order_amount FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;
copy

This query demonstrates how INNER JOIN works to combine information from the customers and orders tables. The query selects the name column from the customers table and the amount column from the orders table. The join condition is specified by the ON clause: customers.customer_id = orders.customer_id. This means that only those rows where a customer has a matching order (that is, the customer_id exists in both tables) will be included in the result. Customers who have not placed any orders—like Charlie Lee and Eve Adams in the sample data—will not appear in the output. Similarly, any order that is not linked to a valid customer would also be excluded, though in the provided data all orders reference existing customers.

1234567891011
SELECT orders.order_id, products.product_name FROM orders INNER JOIN order_products ON orders.order_id = order_products.order_id INNER JOIN products ON order_products.product_id = products.product_id;
copy

1. What does INNER JOIN return if there are no matching records in both tables?

2. Which clause specifies the columns used for joining two tables in an INNER JOIN?

3. Fill in the blanks for an INNER JOIN query joining customers and orders on customer_id.

question mark

What does INNER JOIN return if there are no matching records in both tables?

Select the correct answer

question mark

Which clause specifies the columns used for joining two tables in an INNER JOIN?

Select the correct answer

question-icon

Fill in the blanks for an INNER JOIN query joining customers and orders on customer_id.

SELECT customers.name, orders.order_date FROM customers orders customers.customer_id = orders.customer_id;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 1
some-alt