DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: query help

Threaded View

  1. #6
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    NO UNION - NO NOTHING.

    PHP Code:
    Option In both tables all emp_no are found.
                 
    In this case, use equijoin.

    08:
    05:44 SQLselect from emp1;

        
    EMP_NO LUT
    ---------- --------------------
            
    10 12-SEP-2004 08:04:02
            20 12
    -SEP-2004 08:04:06
            30 02
    -SEP-2004 08:04:25

    08:05:50 SQLselect from emp2 ;

        
    EMP_NO LUT
    ---------- --------------------
            
    10 09-AUG-2004 08:05:21
            20 30
    -AUG-2004 08:05:32
            30 10
    -SEP-2004 08:05:42

    08:05:56 SQLselect a.emp_nogreatest(a.lutb.lut)
    08:
    07:26   2  from emp1 aemp2 b
    08:07:32   3  where a.emp_no b.emp_no ;

        
    EMP_NO GREATEST(A.LUT,B.LUT
    ---------- --------------------
            
    10 12-SEP-2004 08:04:02
            20 12
    -SEP-2004 08:04:06
            30 10
    -SEP-2004 08:05:42

    OPTION 
    EMP2 table has less emp_no.
                 
    Thenyou need to outer join.

    08:
    07:40 SQLdelete emp2 where emp_no 20 ;

    1 row deleted.

    08:08:
    43 SQLcommit;

    Commit complete.

      
    1  select a.emp_nogreatest(a.lutnvl(b.lut,to_date('01-01-1800','DD-MM-YYYY') ))
      
    2   from emp1 aemp2 b
      3
    where a.emp_no b.emp_no(+)
    08:
    13:20 SQL> /

        
    EMP_NO GREATEST(A.LUT,NVL(B
    ---------- --------------------
            
    10 12-SEP-2004 08:04:02
            20 12
    -SEP-2004 08:04:06
            30 10
    -SEP-2004 08:05:42

    Option 
    3 full outer join 

    09:03:40 SQLselect from emp1;

        
    EMP_NO LUT
    ---------- -------------------
            
    10 12/09/2004 08:04:02
            20 12
    /09/2004 08:04:06

    09:08:11 SQLselect from emp2 ;

        
    EMP_NO LUT
    ---------- -------------------
            
    10 09/08/2004 08:05:21
            30 10
    /09/2004 08:05:42

    09:03:33 SQLget emp.sql
      1  select nvl
    (a.emp_nob.emp_no),
      
    2         greatestnvl(a.lutto_Date('01/01/1800','dd/mm/yyyy')) ,
      
    3                   nvlb.lutto_date('01/01/1800','dd/mm/yyyy'))
      
    4                 )
      
    5  from emp1 a full outer join emp2 b
      6
    on a.emp_no b.emp_no
    09:03:38 SQL> /

    NVL(A.EMP_NO,B.EMP_NOGREATEST(NVL(A.LUT,
    ---------------------- -------------------
                        
    10 12/09/2004 08:04:02
                        20 12
    /09/2004 08:04:06
                        30 10
    /09/2004 08:05:42 
    I would suggest to use FULL OUTER JOIN method, if both tables have diff number of rows.

    Tamil
    Last edited by tamilselvan; 09-22-2004 at 10:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width