Mysql 如何在laravel中编写sql连接查询
我有下面的SQL查询,它运行良好 我在数据库(SQL编辑器)中进行了测试Mysql 如何在laravel中编写sql连接查询,mysql,laravel,laravel-5.2,Mysql,Laravel,Laravel 5.2,我有下面的SQL查询,它运行良好 我在数据库(SQL编辑器)中进行了测试 如何执行查询?这是示例。您可以编辑更多内容并使用此查询 $results= \DB::table('groups as b') ->join('group_types as bt', function($join) { $join->on('bt.id', '=', 'b.type_id')
如何执行查询?这是示例。您可以编辑更多内容并使用此查询
$results= \DB::table('groups as b')
->join('group_types as bt', function($join) {
$join->on('bt.id', '=', 'b.type_id')
->where('b.owner_id', '<>', 3);
})
->join('group_users as bu', function($join) {
$join->on('b.id', '=', 'bu.group_id')
->where('bu.status', '=', 'active');
})
->select('b.name','bt.name')
->groupBy('b.name, bt.name')
->get();
$results=\DB::table('groups as b')
->join('group_类型为bt',函数($join){
$join->on('bt.id','=','b.type_id'))
->其中('b.所有者识别号','',3);
})
->join('group\U users as bu',函数($join){
$join->on('b.id','=','bu.group_id'))
->其中('bu.status'、'='、'active');
})
->选择('b.name','bt.name')
->groupBy('b.name,bt.name')
->get();
这是一个示例。您可以编辑更多内容并使用此查询
$results= \DB::table('groups as b')
->join('group_types as bt', function($join) {
$join->on('bt.id', '=', 'b.type_id')
->where('b.owner_id', '<>', 3);
})
->join('group_users as bu', function($join) {
$join->on('b.id', '=', 'bu.group_id')
->where('bu.status', '=', 'active');
})
->select('b.name','bt.name')
->groupBy('b.name, bt.name')
->get();
$results=\DB::table('groups as b')
->join('group_类型为bt',函数($join){
$join->on('bt.id','=','b.type_id'))
->其中('b.所有者识别号','',3);
})
->join('group\U users as bu',函数($join){
$join->on('b.id','=','bu.group_id'))
->其中('bu.status'、'='、'active');
})
->选择('b.name','bt.name')
->groupBy('b.name,bt.name')
->get();
以这个示例为例,修改它
$GetData= Table1::Join('Table2', 'Table1.Id', '=', 'Table2.Id')
->where('MasterId',$MasterId) //optional where clause, if u have any spl condition.
->get();
表1是模型名称
以这个例子,修改它
$GetData= Table1::Join('Table2', 'Table1.Id', '=', 'Table2.Id')
->where('MasterId',$MasterId) //optional where clause, if u have any spl condition.
->get();
表1是模型名称
$GetData= Table1::Join('Table2', 'Table1.Id', '=', 'Table2.Id')
->where('MasterId',$MasterId) //optional where clause, if u have any spl condition.
->get();