如何在Laravel Eloquent中进行完全加入? [英] How to do a full join in Laravel Eloquent?

查看:58
本文介绍了如何在Laravel Eloquent中进行完全加入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在laravel雄辩的情况下,如何在给定两个表t1和t2的情况下执行完全联接?

How do I perform a full join given two tables t1 and t2 in laravel eloquent?

推荐答案

如果您使用的是MySQL.

If you were using MySQL.

MySQL不具有对完全外部联接的内置支持.

MySQL has no inbuilt support for full outer join.

但是您可以使用下面的代码来实现这一目标.

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();

这篇关于如何在Laravel Eloquent中进行完全加入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆