I want to count the number of rows having distinct values on ONLY ONE COLUMN. For example, If I have activities table in which there is email column, I want to count the number of columns having distinct value in email column.
I am using Laravel + PostgreSQL. I tried the following code but it's counting all the rows!
$emailsCount = DB::table('activities')
->where('id',$UserId)
->distinct('email')
->count();
Later, I came to know that distinct() will not take any arguments, I tried to find a solution to my problem and someone(Other Stackoverflow Questions) suggested me to use groupBy just like the following code.
$emailsCount = DB::table('activities')
->where('id',$UserId)
->groupBy('email')
->count();
But it's returning wrong information. For example, In my case, It's returning 1 but I can see lots and lots of different emails in email column. I don't know what's wrong. How can I do this in the right way?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sJanvd
via IFTTT
Aucun commentaire:
Enregistrer un commentaire