B
B
bizzonaru2017-06-08 10:54:47
MySQL
bizzonaru, 2017-06-08 10:54:47

How to get rid of distinct?

There is a table A, to this table by the primary key there are other tables, each of which can contain many identical primary keys of tables A. There are additional selection conditions when querying table A. If you look at the code, it looks like this:

$query = TableA:find()
                ->joinWith(['tableb', 'tablec', 'tablee'], true, 'LEFT JOIN')
      ...

To remove duplicates of TableA, you need to use distinct, which starts to slow down the query a lot when the data in the tables grows. How can I do it differently so that there are no duplicate TableIDs?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim Fedorov, 2017-06-08
@qonand

To remove duplicate TableA, you need to use distinct, which starts to slow down the query a lot when

What are your duplicates? I think you are doing something wrong, or misunderstanding ....

B
bizzonaru, 2017-06-08
@bizzonaru

Duplicates because there are one-to-many tables.

N
n-fom, 2017-06-08
@n-fom

Apparently you have the wrong join. If you post the code of the resulting request here, it will be easier to tell. By itself, the use of distinct indicates an incorrect approach to constructing a query. Alternatively, you can use join with a subquery, if necessary using group by

M
mitaichik, 2017-06-08
@mitaichik

If the relationship is one-to-many, then DISTINCT will not help you, except SELECT to cut it. Here it is necessary to group the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question