sql - Select records with highest salary from duplicate records -


select employee record highest salary duplicate records same name , different salary

id|name|salary 1 |  | 500 2 | b  | 100 3 |  | 400 3 | b  | 200 

output

1 |  | 500 3 | b  | 200 

please post generic sql work on databases.

i have tried below query. not return record if duplicate not exist.

select e.id,e.name,e.salary employee e,     employee e1      e.name = e1.name     , e.salary > e1.salary 

using not exists

select s1.id, s1.name, s1.salary salaries s1 not exists (   select *   salaries s2   s1.name = s2.name , s1.salary < s2.salary ) 

using all

select s1.id, s1.name, s1.salary salaries s1 s1.salary >= all(   select salary   salaries s2   s1.name = s2.name ) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -