【发布时间】:2016-09-21 09:11:14
【问题描述】:
我正在对两个查询进行联合,我想在结果中添加 where 子句,但 where 子句仅添加到第一个查询中。我该如何解决?
$notifications = DB::table('notifications')
->select(DB::raw("notifications.uuid ,notifications.brand_id" ))
$posts = DB::table('posts')
->select(DB::raw("posts.uuid ,posts.brand_id" ))
->unionAll ($notifications)
->orderBy('created_at' , 'desc')
->where('brand_ids' , '=' , '2')
$result = $posts->get();
我想要这条线
->where('brand_id' , '=' , '2')
要添加到整个联合中,但它只添加到其中一个查询中。
【问题讨论】:
-
你不能在两个查询中添加
->where('brand_id', '=', '2'),并在unionAll之前添加第二个(并删除brand_idswhere 子句)?
标签: php mysql laravel laravel-5 union