是否可以在Laravel中按以下方式加入表? [英] Is it possible to join table as below in Laravel?
本文介绍了是否可以在Laravel中按以下方式加入表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在laravel中连接具有多列的两个表,类似下面的查询:
how can I join two tables with multiple columns in laravel, somthing like the below query:
SELECT
*
FROM
tab1 AS e
INNER JOIN
tab2 AS v ON v.Case1 = e.Case1 and v.id = e.id;
我已经在Google中搜索过,但找不到任何方式.
I have searched in google but could not find any way.
这是我到目前为止尝试过的代码:
This is the code I've tried so far:
DB::table('tab1 as e')
->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
->get();
推荐答案
您尝试过以下吗?
DB::table('tab1 as e')
->join('tab2 as v', function($join)
{
$join->on('v.Case1', '=', 'e.Case1');
$join->on('v.id','=', 'e.id');
})
->get();
这篇关于是否可以在Laravel中按以下方式加入表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文