2
I have a table with 5 fields:
- id
- name
- office
- salary
- date
...and wanted to make a query that returns the name of the people with the highest salary, of each position, and I have for example 3 positions: analyst, dev and engineer.
With this script I can bring the highest salary for example from the ANALYST position, but how to bring from the other two, being that this table has no relationship?
SELECT nome, cargo, salario from vendedor
where salario = (SELECT max(salario) from vendedor)
what does this mean (select 1??) worked out the query changed the parameters of the column etc etc...
– Everson Souza de Araujo
@Eversonsouzadearaujo o
SELECT 1
is just to force some outcome toquery
be satisfied, since the result does not interfere in anything. The secret of the operation is theEXISTS
. I’ll put a reference to it in the answer– Sorack
@Eversonsouzadearaujo put in Sqlfiddle the query working together with another possible example: http://sqlfiddle.com/#! 6/afd0c/5
– Rovann Linhalis
@Sorack thank you
– Everson Souza de Araujo