I have the following table:
I need to count the number of records where supplier_id
equals 2 but does not repeat the order_id
column. In that case it would return 1, since it has two records with 2 in supplier_id
, but order_id
is 1 in both records
I used the query below in mysql and correctly returned 1 record:
SELECT COUNT(DISTINCT order_id) FROM timelines WHERE supplier_id = 2;
I used the query below in Laravel and it returned me 2 records
DB::table('timelines')
->where('supplier_id', 2)
->groupBy('order_id')
->count();
How could I do to return the correct quantity which in the case is 1 record?