#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    What should be the right SQL query?


    My table is:
    Code:
       EMP_NUM EMP_FNAME  EMP_LNAME         JOB  HIREDATE
    ---------- -------------------- -------------------- ---
           101 John                 News                 DBD  01-NOV-78
           102 David                Senior                SYA 03-OCT-88
           103 June                 Arbough             EEG  23-JUN-99
           105 Alice                Johnson              DBD  15-AUG-95
           106 William              Smithfield           PRG  31-OCT-02
           118                      Frommers                     02-NOV-04
           120 subir                adhikari               DBD  20-APR-15
    I wrote a SQl quesry to find "the higher hiredates from the minimum hiredate for those whose job='DBD'
    So I wrote:
    Code:
      
    select * from emp
     where hiredate>any(select hiredate from emp where job_code='DBD');
    But the result I got is:
    Code:
    120	subir               	adhikari            	DBD	20-04-15
    118		Frommers            		        02-11-04
    106	William             	Smithfield          	PRG	31-10-02
    103	June                	Arbough             	EEG	23-06-99
    105	Alice               	Johnson             	DBD	15-08-95
    102	David               	Senior              	SYA	03-10-88
    So you see I got every bodies hiredate whether it is 'DBD' or not. So what should be the right SQL query to display the right data?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    845
    Rep Power
    387

    Cool


    Originally Posted by mistu4u
    I wrote a SQl quesry to find "the higher hiredates from the minimum hiredate for those whose job='DBD'
    . . . Etc ...
    So you see I got every bodies hiredate whether it is 'DBD' or not. So what should be the right SQL query to display the right data?
    The requirement is confusing, but if I understood correctly, it should be kinda like this:
    Code:
    SELECT *
      FROM emp
     WHERE hiredate > (
            SELECT MIN (hiredate)
              FROM emp
             WHERE job_code = 'DBD');

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo