MySQL straight_join
时间: 2023-07-26 17:03:34 浏览: 79
MySQL `STRAIGHT_JOIN` is a query modifier that instructs the MySQL optimizer to join the tables in the order they are specified in the `FROM` clause. Normally, the optimizer decides the join order based on the cost-based optimization algorithm, which may not always result in the best performance. By using `STRAIGHT_JOIN`, you can force MySQL to use the join order you specified, which may be more efficient in certain cases.
Here's an example of using `STRAIGHT_JOIN`:
```
SELECT *
FROM table1 STRAIGHT_JOIN table2 ON table1.id = table2.id
WHERE table1.column = 'value';
```
In this example, we are joining `table1` and `table2` on the `id` column, and filtering the result by the `column` value in `table1`. By using `STRAIGHT_JOIN`, we are telling MySQL to join `table1` and `table2` in the order they are specified in the `FROM` clause.
阅读全文