I have a table with the columns nome
, salario
and alocacao
.
How do I select only the worker who has the highest salary and who has the value mg
in the alocacao
column, without using MAX()
?
I have a table with the columns nome
, salario
and alocacao
.
How do I select only the worker who has the highest salary and who has the value mg
in the alocacao
column, without using MAX()
?
SELECT
nome, salario
FROM empregados
WHERE alocacao="mg"
ORDER BY salario DESC
LIMIT 1
Pieces:
nome
, salario
, the columns you want to appear in the result FROM empregados
, the table name WHERE alocacao="mg"
, the condition to be verified, ie. only bring result (s) that has (m) the value of column alocacao
equal to 'mg' 'ORDER BY salario
, sort by column value salario
DESC
, make sorting in descending order (from highest to least) LIMIT 1
, bring only one result