writting distinct query example
i need show the unique values for whole table i have searched in google the query written was
DB::table('products')->select('color')->distinct()->get();
the above query displays the unique color value
how to query for whole table
(correct me if i am wrong)
DB::table(products')->select('*')->distinct()->get();
Have you actually tried the query?
@bobbybouwmann i have tried with below query it displays the unique value of colors
DB::table('products')->select('color')->distinct()->get();
other query like below won't displays the unique value
DB::table('products')->select('*')->distinct()->get();
Probably because you don't specify which column should be unique here. I think Laravel doesn't support this and you need to write a raw query for it!
@bobbybouwmann that's fine sir thank you.can you give me a example of writting raw query of it.??
Like I said, you need a raw query!
@bobbybouwmann not getting to write raw query using above link!! there is no example for using distinct clause!!
Well distinct in a sql keyword. You should write a normal SQL query and perform that on your database
Please or to participate in this conversation.