【问题标题】:How to perform outer join in laravel for mysql如何在laravel中为mysql执行外连接
【发布时间】:2021-03-10 02:37:50
【问题描述】:

我想在 Laravel 中对 Mysql 执行完全外连接。(我知道 Mysql 不支持完全外连接) 我想选择 id=$formId 的 table1 的所有字段和 table2 的一个字段。

       DB::table('forms')
            ->leftJoin('answers',function($join) use($formId){
                $join->on('forms.formid', '=' ,'answers.formid')
                ->where('forms.formid',$formId);
            })
            ->select('forms.*','answers.uniqid')
            ->get();

但是 where 条件不起作用?

【问题讨论】:

标签: mysql laravel


【解决方案1】:

我改变了我的位置,它解决了我的问题。

      DB::table('forms')
            ->leftJoin('answers',function($join) use($formId){
                $join->on('forms.formid', '=' ,'answers.formid');
            })
            ->where('forms.formid','109')
            ->select('forms.*','answers.uniqid')
            ->get();

但是 Laravel Doc 定位到 join 函数的位置!

  DB::table('users')
    ->join('contacts', function ($join) {
        $join->on('users.id', '=', 'contacts.user_id')
             ->where('contacts.user_id', '>', 5);
    })
    ->get();

Laravel Docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-26
    • 2018-02-10
    • 1970-01-01
    • 2018-04-08
    • 2011-12-31
    • 1970-01-01
    • 2014-09-17
    • 2015-06-05
    相关资源
    最近更新 更多