None
None

Reputation: 9247

Distinct is not working?

  $data = Districts::distinct()->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->select('region', 'district')->get();

I have this query, but problem is that distinct not working. I get for example three records for same thing. Any suggestion?enter image description here

Upvotes: 1

Views: 946

Answers (3)

ram pratap singh
ram pratap singh

Reputation: 53

use this to get one

$data = Districts::select([ DB::raw('DISTINCT(district)'),'region'])->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->first();

Upvotes: 0

ram pratap singh
ram pratap singh

Reputation: 53

try to this may i think its could be work with region

  $data = Districts::select([ DB::raw('DISTINCT(district)'),'region'])->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->get();

Upvotes: 0

ram pratap singh
ram pratap singh

Reputation: 53

try to this may i think its could be work

  $data = Districts::select( DB::raw('DISTINCT(district)'))->whereRaw('LOWER(district) like ?', [strtolower('%'.$district . '%')])->orWhereRaw('LOWER(region) like ?', [strtolower('%'.$district . '%')])->get();

Upvotes: 1

Related Questions