How to get distinct rows in laravel?

Member

by deron , in category: PHP Frameworks , a year ago

How to get distinct rows in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , a year ago

@deron 

To get distinct rows in Laravel, you can use the distinct() method in your query.


Here is an example:

1
2
3
4
$distinctRows = DB::table('users')
             ->select('name')
             ->distinct()
             ->get();


This query will return only distinct rows of the name column from the users table. You can modify the select() and distinct() methods according to your requirements to get distinct rows based on specific columns.

Related Threads:

How to get 2 distinct rows from 1 row with 3 tables in sql oracle?
How to get distinct value from array in javascript?
How to get distinct values in d3.js?
How to get distinct values from nested table in oracle?
How to get num rows in Codeigniter?
How to get all the rows from mysql table in codeigniter?