How to select the name and salary of the employee of 'MG' who receives the highest salary? [closed]

2

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() ?

    
asked by anonymous 22.04.2017 / 19:54

1 answer

6
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
22.04.2017 / 19:57