Sorting with ORDER BY · Ordenação com ORDER BY
Sorting the result
The rows come back in no particular order. Add ORDER BY to sort them by a column:
ASCsorts ascending (smallest first) — this is the default.DESCsorts descending (largest first).
Ordenando o resultado
As linhas retornam em uma ordem arbitrária. Adicione ORDER BY para ordená-las por uma coluna:
SELECT name, score FROM student ORDER BY score DESC;
ASCordena em ordem crescente (menor primeiro) — esta é a padrão.DESCordena em ordem decrescente (maior primeiro).
Sorting by more than one column
Sort text columns alphabetically:
You can sort by several columns: ORDER BY form ASC, score DESC sorts by form first, then by score within each form. ORDER BY always comes last in the query.
Ordenando por mais de uma coluna
Ordene colunas de texto alfabeticamente:
SELECT name FROM student ORDER BY name;
Você pode ordenar por várias colunas: ORDER BY form ASC, score DESC ordena primeiro pela turma, depois pela nota dentro de cada turma. ORDER BY sempre vem no final da consulta.
Common mistakes
- The default sort is ascending; add
DESCfor descending. ORDER BYcomes near the end of the query.
Erros comuns
- A ordenação padrão é crescente; adicione
DESCpara decrescente. ORDER BYfica perto do final da consulta.
ORDER BY sorts the rows · ORDER BY ordena as linhas
ORDER BY puts the result rows in order, like a sort. · ORDER BY organiza as linhas resultantes em ordem, como uma ordenação.
Show every student's name and · e score, highest score first. · Exiba a name e a score de todos os alunos, nota mais alta primeiro.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Show every student's name, sorted alphabetically (A to Z). · Exiba a name de todos os alunos, ordenados alfabeticamente (A a Z).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.