how to use union and intersection in laravel query

Solutions on MaxInterview for how to use union and intersection in laravel query by the best coders in the world

showing results for - "how to use union and intersection in laravel query"
Emilia
06 Mar 2020
1$queryWithParent = SaleService::query()
2    ->select(\DB::raw('DISTINCT ON (properties.parent_id) sale_services.*'))
3    ->from('sale_services')
4    ->join('properties', 'sale_services.property_id', '=', 'properties.id')
5    ->whereNotNull('properties.parent_id')
6    ->orderBy('properties.parent_id')
7    ->orderBy('sale_services.index_range', 'desc');
8
9$queryWithoutParent = SaleService::query()
10    ->select(\DB::raw('sale_services.*'))
11    ->join('properties', 'sale_services.property_id', '=', 'properties.id')
12    ->whereNull('properties.parent_id');
13
14$query = $queryWithParent->union($queryWithoutParent);