samedi 29 juin 2019

Selection of unique records by one field

I need to select only entries with a unique values 'who_id'

    $history_today = DB::table('view_history')
            ->select('girl_id', 'who_id', 'girls.name as name', 'girls.main_image', 'view_history.time', 'girls.age',
                'cities.name as city_name', 'girls.city_id')
            ->where('girl_id', $girl->id)
            ->where('who_id', '!=', null)
            ->where('who_id', '!=', $girl->id)
            ->leftJoin('girls', 'girls.id', '=', 'view_history.who_id')
            ->leftJoin('cities', 'girls.city_id', '=', 'cities.id_city')
            ->orderBy('time', 'DESC')
            ->distinct('who_id')
            ->paginate(15);

But in this case, I get all the records.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire