SQL Inner Join
An SQL INNER JOIN is used to combine rows from two or more tables based on a related column between them. It returns only the matching rows between the tables.etween the tables.
The basic syntax for an INNER JOIN is as follows:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;
Here’s an example to illustrate how it works. Suppose we have two tables:
customers table has columns
orders table has columns
order_date. We want to retrieve the orders along with the customer information. We can use the following query:
SELECT orders.order_id, customers.customer_name, customers.email, orders.order_date FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id;
In this example, we specify the columns we want to select from both tables. We join the
orders table with the
customers table using the
INNER JOIN keyword and specify the join condition with the
ON keyword. The join condition in this case is the equality between the
customer_id columns of both tables.
The result of the query will include only the rows where there is a match between the
customer_id values in both tables. The selected columns from both tables are included in the result set.
Note that you can join more than two tables using multiple
INNER JOIN statements.