D
D
dargezrogue2020-06-19 09:25:39
SQL
dargezrogue, 2020-06-19 09:25:39

How to get unique records from a database?

There is a column in the bot_orders table in the database that stores dates in string form
5eec5a10dea31431908411.png
. Please tell me how to make a query through the builder or the BotOrder model to get only unique records for this column.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2020-06-19
@dargezrogue

BotOrder::select('date_of_creating')->distinct()->get();

I
Ivan Koryukov, 2020-06-19
@MadridianFox

In order for the sql query to give you only unique rows , you need to add the word distinct to the select section.
Like this: Roughly the same can be done through eloquent builder However, this works with response lines. If your response lines are different, but the date is repeated, then a more complex solution is needed there.
select distinct id, name, date...
Model::query()->distinct()...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question