mysql inerll join
时间: 2023-10-13 19:22:32 浏览: 32
An INNER JOIN in MySQL is a type of join that returns only the rows that have matching values in both the tables being joined. It is used to combine rows from two or more tables based on a related column between them.
The syntax for an INNER JOIN in MySQL is as follows:
```
SELECT column1, column2, ...
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
```
In this example, `table1` and `table2` are the names of the tables to be joined, and `column` is the column in both tables that has matching values. The `SELECT` statement specifies which columns to retrieve from the joined tables.
For example, suppose we have two tables `customers` and `orders`, with a common column `customer_id`. We can use an INNER JOIN to retrieve all orders for each customer:
```
SELECT customers.customer_name, orders.order_date, orders.order_total
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
```
This will return a result set with columns `customer_name`, `order_date`, and `order_total`, showing all orders for each customer. Only the rows where there is a matching `customer_id` value in both tables will be included in the result set.