I got database table like this:
**job_id**
5
5
5
6
6
7
8
8
I want to write query, which could select only unique id's. By saying unique I mean select only these values once:5, 6, 7, 8
Thanks in advance!
You could use DISTINCT.
DB::table('table')->select('job_id')->distinct()->get();
How about:
$jobs = DB::table('my_job_table')
->groupBy('job_id')
->get();
Eloquent:
php artisan make:model jobs
(I assume you have done this already) This will create a model in /your_project/app/Job.phpNow you can use Eloquent (here in a route, to see some output):
Route::get('/jobs', function () {
$jobs = \App\Job::groupBy('job_id')->get();
return $jobs->lists('job_id');
});
will return something like: [0,1,3,4]
instead of [0, 1, 1, 1, 3, 4, 4, 4]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With