Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to use union and intersection in laravel query

$queryWithParent = SaleService::query()
    ->select(DB::raw('DISTINCT ON (properties.parent_id) sale_services.*'))
    ->from('sale_services')
    ->join('properties', 'sale_services.property_id', '=', 'properties.id')
    ->whereNotNull('properties.parent_id')
    ->orderBy('properties.parent_id')
    ->orderBy('sale_services.index_range', 'desc');

$queryWithoutParent = SaleService::query()
    ->select(DB::raw('sale_services.*'))
    ->join('properties', 'sale_services.property_id', '=', 'properties.id')
    ->whereNull('properties.parent_id');

$query = $queryWithParent->union($queryWithoutParent);
Comment

PREVIOUS NEXT
Code Example
Php :: preg_split 
Php :: check if input file is empty in php 
Php :: how do i know if file is empty in php 
Php :: php one line if without else 
Php :: if statement in laravel blade 
Php :: how to run php in js 
Php :: laravel resource api 
Php :: laravel pagination limit page 
Php :: php configuration in apache server 2.4 
Php :: install a package only composer dont update 
Php :: laravel sanctum Provoking tokens 
Php :: laravel crud 
Php :: disadvantages of php 
Php :: laravel api 
Php :: carbon get month from date 
Php :: laravel public static variable 
Php :: codeigniter select where 
Php :: laravel seeder with relationships 
Php :: specify php version composer 
Php :: limit query codeiniter 3 
Php :: php max 
Php :: like button phpAdd Answer 
Php :: get posts with multiple meta value in wordpress 
Php :: php namespaces 
Php :: laravel 7 requirements 
Php :: php get referrer ajax 
Php :: access model in config laravel 
Php :: phpspreadsheet select sheet 
Php :: You need to grant write permissions for PHP on the following directory: /var/www/html/prestashop 
Php :: laravel model create get id 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =