Reputation: 227
I've been using Laravel for a little while now and really enjoying it,however I seem to have come unstuck using the query builder.
I have multiple UNIONS in my query which is all working exactly how I'd like however when I add the ->take() method to limit my results something a little strange happens, instead of the limit sitting at the end of my query it sits inside the first select.
Example as it stands:
(select * FROM fruit LIMIT 1) union (select * FROM veg)
Example of how I'd like it to work:
(select * FROM fruit) union (select * FROM veg) LIMIT 1
BASIC CODE EXAMPLE:
$fruit = DB::table('fruit')
->select(*);
$veg = DB::table('veg')
->select(*);
$query = $fruit->union($veg)->take(1)->get();
return $query;
Has anyone suffered the same issue? More importantly has anyone managed to resolve this issue? I've been searching for hours for a resolve so any help would be greatly appreciated.
Upvotes: 2
Views: 4647
Reputation: 4500
Edit, sorry, this won't work either, indeed the FQB doesn't know union.
Would rather advise you building this with Eloquent, but if you want to do it this way, this might work:
$fruit->union($veg)->first();
Upvotes: 2