Hi I am using Laravel 10 . My issue is not able to use orderby() with distinct().
I am using PostgreSQL as database. When I tried Group_by , I am getting repeated results. I have tried many solutions found here, but nothing works for me.
My Query
$property = DB::table('properties')
->leftjoin('property_sub_types', 'property_sub_types.id', '=', 'properties.property_sub_type')
->leftjoin('property_images', 'properties.id', '=', 'property_images.property_id')
->leftjoin('cities', 'cities.id', '=', 'properties.city')
->select('properties.name as proName', 'properties.id as pro_id', 'properties.city', 'properties.street', 'property_sub_types.name as subName', 'property_images.image as imgName','cities.name as ctyName','properties.reserve_price','properties.description','properties.possession','properties.ownership','properties.auction_start_date','properties.contact_manager','properties.contact_number', 'properties.updated_at')
->where('properties.property_status', 4)
->where('properties.status', 1)
->where('property_sub_types.status', 1)
->orderBy('properties.updated_at')
->distinct('properties.id')
->paginate(30);
Error showing as
SQLSTATE[42P10]: Invalid column reference: 7 ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions LINE 1: select distinct on ("properties"."id")
->orderBy('properties.id') ->orderBy('properties.updated_at')I have added this and getting results also but, results orderby properties.id not by updated_atdistinct()with no argument.