Skip to content

PHP code snippet – How to use union and intersection in laravel query?

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

$queryWithoutParent = SaleService::query()
    ->join('properties', 'sale_services.property_id', '=', '')

$query = $queryWithParent->union($queryWithoutParent);
See also  How to put comments in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.