-1

I have this table patients

patient_id | job

  2          nurse
  2          carpenter
  1          programmer

It should count 2 because it didnt include the same id

does anyone know a query for that? I'm using laravel

and this is my code so far

App\Notification::select('patients.*',DB::raw('count(*) as total'))
Christian
  • 417
  • 1
  • 5
  • 11

3 Answers3

1
App\Notification::distinct('patient_id')->count();
Neabfi
  • 4,411
  • 3
  • 32
  • 42
0

try

SELECT COUNT(DISTINCT patient_id) FROM table_name;

that should work ... sorry ... had them backwards before

0

Using Eloquent, you can do something like this:

$noti = \App\Notification::groupBy('patient_id')->get();
$count = $noti->count();
geckob
  • 7,680
  • 5
  • 30
  • 39