Home Laravel Example of unionAll in Query Builder Laravel

Example of unionAll in Query Builder Laravel

by Shahriar Sagor

Sometimes you need to bind multimple query then you can use unionAll in laravel. If we are use union all then laravel query builder provide unionAll method for mysql union. when we are doing with a big project or ERP level project then mostly we have require to use union for getting data from database with the multiple table. Now in following example we can see how to use union all in Laravel application.

Example:

$silver = DB::table("product_silver")
    ->select("product_silver.name"
      ,"product_silver.price"
      ,"product_silver.quantity");
$gold = DB::table("product_gold")
    ->select("product_gold.name"
      ,"product_gold.price"
      ,"product_gold.quantity")
    ->unionAll($silver)
    ->get();
print_r($gold);

Read Also : Laravel Join with Subquery in Query Builder Example

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

close

You may also like