Solved

simple Oracle query question

Posted on 2007-12-04
6
1,109 Views
Last Modified: 2013-12-18
let say i have the foolowing table/data
OFFICER: Officer no
                 Officer name
      Officer address
         Officer Date-of-Birth
how do i show all the officers who are older than a given officer
0
Comment
Question by:aaxen
6 Comments
 
LVL 8

Expert Comment

by:YANN0S
ID: 20405402
SELECT <whatever you want to select>
WHERE yourtable
WHERE
SELECT <whatever you want to select from a>
  FROM yourtable a
 WHERE EXISTS (SELECT 1 FROM a.birthdate < b.birthdate
   AND <whatever criteria you use to identify the given officer >)

Open in new window

0
 
LVL 8

Expert Comment

by:YANN0S
ID: 20405420
Sorry, repost
SELECT <whatever you want to select from a>
  FROM yourtable a
 WHERE EXISTS (SELECT 1 
                 FROM  yourtable b 
                WHERE a.birthdate < b.birthdate
                  AND <whatever criteria you use to identify the given officer >)
 

Open in new window

0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20405430
I hope it should be like this.

declare @dob datetime
set @dob ='12/12/1960'
select * from OFFICER where  Officer Date-of-Birth
>=@age
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20405432
declare @dob datetime
set @dob ='12/12/1960'
select * from OFFICER where  Officer Date-of-Birth
<=@age
0
 
LVL 27

Accepted Solution

by:
sujith80 earned 500 total points
ID: 20408786
select * from Officer
where officer_date_of_birth < ( select officer_date_of_birth
                                from Officer
                                where officer_no = <your value> )
/
0
 

Author Comment

by:aaxen
ID: 20410237
hi yannos saw your code just one question, What does the " select 1 "means
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question