If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > qryhelp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-03, 01:03
vadlamanibujji vadlamanibujji is offline
Registered User
 
Join Date: Oct 2002
Posts: 36
qryhelp

Hello


how to retrieve the employees info who are earning more than the oldest employee.

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-09-03, 04:33
umciggy umciggy is offline
Registered User
 
Join Date: Jan 2003
Posts: 16
Re: qryhelp

Quote:
Originally posted by vadlamanibujji
Hello


how to retrieve the employees info who are earning more than the oldest employee.

Thanks
select * from emp where salary >
(select salary from emp where age=(select max(age) from emp))
Reply With Quote
  #3 (permalink)  
Old 01-09-03, 06:39
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: qryhelp

Quote:
Originally posted by umciggy
select * from emp where salary >
(select salary from emp where age=(select max(age) from emp))
That works if only one employee has the max(age), otherwise it will give error:

ORA-01427: single-row subquery returns more than one row

In case there are 2 or more employees with max(age), you could specify the min(salary) or the max(salary):

select * from emp where salary >
(select max(salary) from emp where age=(select max(age) from emp))
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On