user83358 user83358 - 4 months ago 32x
SQL Question

Is there a way to create a STRAIGHT_JOIN using Laravel's ORM?

I have one query where I need to use a STRAIGHT_JOIN for performance reasons. The query is built like this:

$query->join('tbl2 as b', function ($join) {
$join->on('a.b_id', '=', '')
->where('b.x_id', $x);

Is there any way to force the query to use STRAIGHT_JOIN? It looks like this is impossible because there's no space (like you would have with INNERT JOIN, LEFT JOIN, etc).


It appears that SELECT STRAIGHT_JOIN <cols> ... solves the problem. This can be done relatively easily by manipulating the list of columns to select and automatically applies to all joins in the query.