I have a table like this:
I want to get distinct row from this. I use:
DB::table('dmspro_mys_campaign_product')->distinct()->get();
But it still give result with 3 rows. I expected 2 rows.
How I can fix this?
I have a table like this:
I want to get distinct row from this. I use:
DB::table('dmspro_mys_campaign_product')->distinct()->get();
But it still give result with 3 rows. I expected 2 rows.
How I can fix this?
Simply pass the field name inside the distinct function. like this(in case if you want distinct based on 'compeign_code' column)
DB::table('dmspro_mys_campaign_product')->distinct('compeign_code')->get();
in case if you want to distinct the field based on more than one column value then you can use the select method.
In my opinion the answer is correct. District rows give you the results where every row is unique. Since there are slight variations between all three rows, you get all three because no row is exactly equal to another row.
I hope I could help, Sebastian
You need a distinct value from dmspro_mys_campaign_product
table so Database query needs pass column name.
DB::table('dmspro_mys_campaign_product')->distinct('product_id')->get();
You simply need to mention the column name in distinct('compeign_code')
.
DB::table('dmspro_mys_campaign_product')->distinct('compeign_code')->get();
Or you can try
DB::table('dmspro_mys_campaign_product')->groupby('product_id')->distinct()->get();
If you want to get only one column then you may use this.
DB::table('dmspro_mys_campaign_product')->distinct()->select('product_id');