"order by clauses" can create conflicts between themselves?

Asked

Viewed 36 times

2

It is possible that if we have several clauses in the order by, these conflict with each other? For example:

select candidato.nome
from candidato, perfil_oferta, prova_de_afericao
where candidato.bi = prova_de_afericao.cod_prova and
prova_de_afericao.nr_identificacao = perfil_oferta.nr_identificacao and 
prova_de_afericao.classificacao > 
(select avg(prova_de_afericao.classificacao) from prova_de_afericao)
order by 
        perfil_oferta.nr_identificacao DESC, 
        prova_de_afericao.cod_prova DESC, 
        candidato.nome ASC;

The result cannot be ordered simultaneously according to the 3 clauses, so my question is whether there is any priority associated with the clauses, or how they are organized if it is not possible to arrange an order that satisfies the 3 clauses.

1 answer

4


If I understand your question correctly the answer is no.

In the ORDER BY clause, priority is given to whoever is defined first.

Explaining using your example:

The bank will be ordered using the directory.nr_identification number.

If there is a conflict in the nr_identification field, then this conflict will be solved by ordering cod_proof, also nonreference.

If there is conflict both in nr_identification and in cod_proof, then the last criterion will be used for tiebreaker.

Note that other ordinations are only used when there has been "conflict", so one will not influence the other to the point of conflict.

If you have any questions, you can consular the following link (in English) https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html

  • Thank you, the link was useful, already clarified my doubt.

  • Yes, your order by clause will return exactly like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.