How to use Union query with Laravel Eloquent?By Hardik Savani | September 18, 2018 | | 9003 Viewer | Category : PHP Laravel
In this post, i would like to share with you how we can use union and union all query in laravel 5 application.
Laravel eloquent provide query builder and they give us join, relationship, subquery and also union. But we need some time to get all records from two different table at that time you need to use union or union all query. So here i am going to give you very simple example with tables and also show you output of result.
Here we will create two tables "product_silver" and "product_gold" with dummy data like as bellow. Then after we will write union query and result also i shown as screenshot, so let's see bellow:
$silver = DB::table("product_silver")
$gold = DB::table("product_gold")
I hope it can help you....
- Laravel - How to make subquery in select statement?
- Laravel 5 select with count query with group by example
- Laravel 5 select with sum query example
- How to select concat columns with Laravel Query Builder?
- Example of unionAll in Query Builder Laravel 5
- Laravel 5 Join with subquery in Query Builder Example
- How to add pagination with union in Laravel 4 and Laravel 5 ?