简体   繁体   English

如何在 Laravel Eloquent 中进行完全加入?

[英]How to do a full join in Laravel Eloquent?

给定两个表 t1 和 t2 在 laravel eloquent 中,如何执行完全连接?

If you were using MySQL.如果您使用的是 MySQL。

MySQL has no inbuilt support for full outer join. MySQL 没有对完全外连接的内置支持。

But you can use the code like this below to achieve that.但是你可以使用下面这样的代码来实现这一点。

$table2 = DB::table('t2')
         ->rightJoin('t1', 't1.id', '=', 't2.t1_id')

$table1 = DB::table('t1')
        ->leftJoin('t2', 't1.id', '=', 't2.t1_id')
        ->unionAll($table1)
        ->get();

Most of query builder join functions have an optional argument called $type ='inner'大多数查询构建器连接函数都有一个名为$type ='inner'的可选参数
so if you database supports full join (eg: postgres) just pass "full" as the $type parameter因此,如果您的数据库支持完全连接(例如:postgres),只需将“full”作为 $type 参数传递

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM