Using the MAX aggregate between two tables

I have two tables, employer and position:

employer
Eid
ENAME


Eid
Salary Position

I need to match my eID between two tables, determine the maximum salary and print only eName. Any suggestions on how I can do this? I tried several ways, but nothing works.

I am not sure where to introduce the maximum (salary) function:

select eName
from employer, position
where employer.eID = position.eID
+3
source share
3 answers

To get the name (s) of the people with the highest salary ...

Using JOIN:

SELECT e.name
  FROM EMPLOYER e
  JOIN POSITION x ON x.eid = e.eid
  JOIN (SELECT MAX(salary) AS max_salary
          FROM POSITION) y ON y.max_salary = x.salary

Using a subquery:

SELECT e.name
  FROM EMPLOYER e
  JOIN POSITION p ON p.eid = e.eid
 WHERE p.salary = (SELECT MAX(salary)
                     FROM POSITION)
+3

, :

select top 1 e.eName, p.salary
from Employer e
inner join Position p on p.eID = e.eID
order by p.salary desc

( , , , , .)

0
select e.ename,p.salary
from employer e ,position p
where p.salary=(select max(salary) from position)
and e.eid=p.eid
0
source

Source: https://habr.com/ru/post/1766462/


All Articles