在laravel中左连接查询

时间:2017-03-07 05:13:20

标签: php mysql laravel

如何查询

SELECT * FROM your_table WHERE FIND_IN_SET('2017-03-08',comma_date );

laravel版本中的

2 个答案:

答案 0 :(得分:2)

$result = DB::table('client_invoice as a')
->leftjoin('document as b', 'a.client_invoice_id', '=', 'b.relation_id_invoice')
->whereNotNull('a.client_invoice_id')
->where('b.type_document', '=', 'client_invoice')
->distinct()
->count();

答案 1 :(得分:1)

Laravel离开了加入:

$users = DB::table('users')
            ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
            ->get();

或者您可以使用Raw Expression,例如:

$users = DB::table('users')
                     ->select(DB::raw('count(*) as user_count, status'))
                     ->where('status', '<>', 1)
                     ->groupBy('status')
                     ->get();

Laravel Left Join

Laravel Raw Expression