A
A
aden2017-04-05 01:35:10
MySQL
aden, 2017-04-05 01:35:10

Is it possible in yii2 Active Record to get two fields with distinct on one of them?

Actually, you need to get a list of names of certain entities along with their id, but the distinct () method seems to work only if you select one column of data, do you really need to write bare sql?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
padlyuck, 2017-04-05
@aden

Perhaps I misunderstood the question, but how do you imagine it? If you make a query like SELECT DISTINCT some_field, id FROM some_table; the database will return non-repeating combinations of some_field and id fields. And since id you most likely have a primary key, then it will be unique for each record, which means that the situation when there are several records in some_table for which some_field and id are pairwise equal is impossible in principle. Show the request itself which you want to receive as a result?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question