The INNER JOIN keyword selects records that have matching values in both tables. It returns only rows where a match exists between the joined tables' columns.
INNER JOIN excludes rows without matching counterparts.ON to specify the equality between common columns.INNER JOIN clauses to combine several tables.
-- Syntax for INNER JOIN
SELECT columns
FROM table1
INNER JOIN table2
ON table1.common_column = table2.common_column;
-- Get all students and their corresponding courses
SELECT students.name, courses.course_name
FROM students
INNER JOIN courses
ON students.course_id = courses.course_id;
-- Get all orders and their related customer information
SELECT orders.order_id, customers.customer_name
FROM orders
INNER JOIN customers
ON orders.customer_id = customers.customer_id;
The queries above will return only rows where the join condition matches. For example, the student-course query returns rows for students who have a course_id that exists in the courses table. Any student without a matching course_id will be excluded.
Use LEFT JOIN if you want to include all rows from the left table even when there is no match on the right table.
INNER JOIN.INNER JOIN between customers and orders.