The issue with using the multiple columns sub-query in WHERE clause

Hi All,
my database version is 10.2.
the problem i am trying to deal with is that when I use multiple column sub-query in the WHERE clause of the SELECT statement, the actual row number returned from the sub-query is different from the whole statement.
And what I found is that, whenever there is NULL in any of those columns returned from the SUB-QUERY, the outer query will just return NULL for that whole row.
Here is an example:
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job,  mgr, hiredate, sal, deptno from t;
7782     CLARK     MANAGER     7839     09-JUN-81     2450     10
7839     KING     PRESIDENT  NULL  17-NOV-81     5000     10
7934     MILLER     CLERK     7782     23-JAN-82     1300     10
select * from EMP where (EMPNO, ENAME, job, MGR, HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job,  mgr, hiredate, sal, deptno from t);
7782     CLARK     MANAGER     7839     09-JUN-81     2450          10     
7934     MILLER     CLERK     7782     23-JAN-82     1300          10     If I specifically deal with the NULL situations for the columns which might return NULL, I can get the result right.
select * from EMP where (EMPNO, ENAME, job, NVL(MGR,-1), HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from EMP
intersect
select empno, ename, job,  nvl(mgr,-1), hiredate, sal, deptno from t);
7782     CLARK     MANAGER     7839     09-JUN-81     2450          10     
7839     KING     PRESIDENT  null   17-NOV-81     5000          10     
7934     MILLER     CLERK     7782     23-JAN-82     1300          10     the problem is that, I feel this is a very lame way of handling it.
So, I wonder or am asking if there is any better or standard way to do it?
any help would be highly appreciated.
Thanks

Hi,
As you discovered, INTERSECT treats NULL as a value, but IN does not.
What you did with NVL is one way to handle the situation. If there was a chance that any of the columns could be NULL, then you might prefer something like this:
select      *
from      EMP
where      ( EMPNO      || '~' ||
       ENAME      || '~' ||
       job           || '~' ||
       MGR           || '~' ||
       TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
                || '~' ||
       SAL           || '~' ||
       DEPTNO
     ) in (
          select  EMPNO      || '~' ||
                 ENAME      || '~' ||
               job     || '~' ||
               MGR     || '~' ||
               TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')               
                    || '~' ||
               SAL      || '~' ||
               DEPTNO
          from     emp
         intersect
          select  EMPNO      || '~' ||
                 ENAME      || '~' ||
               job     || '~' ||
               MGR     || '~' ||
               TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')               
                    || '~' ||
               SAL      || '~' ||
               DEPTNO
          from      t
         );This assumes that you can identify some string (I used '~') that never occurs in the strings in these tables.
This is implicitly converting the NUMBERs. That's usually not a good thing to do. but explicitly converting them would make this even more tedious.
You should explicitly convert any DATEs to strings, however. Depending on your default format, and your data, you might get away with implicit conversions even for DATEs, but don't bet on it.
If you had to do this often, you might consider writing a user-defined function:
delimited_string (empno, ename, job, mgr, hiredate, sal, deptno) would return a string like
'7839~KING~PRESIDENT~~17-NOV-1981~5000~10'
This will make the coding easier, but beware: it will make the execution slower.

Similar Messages

  • Issues with using the output redirection character with newer NXOS versions?

    Has anyone seen any issues with using the output redirection character with newer NXOS versions?
    Am receiving "Error 0x40870004 while copying."
    Simply copying a file from bootflash to tftp is ok.
    This occurs for both 3CDaemon and Tftpd32 softwares.
    Have tried it on multiple switches - same issue.
    Any known bugs?
    thanks!
    The following is an example of bad (NXOS4.1.1b) and good (SANOS3.2.1a)
    MDS2# sho ver | inc system
      system:    version 4.1(1b)
      system image file is:    bootflash:///m9200-s2ek9-mz.4.1.1b.bin
      system compile time:     10/7/2008 13:00:00 [10/11/2008 09:52:55]
    MDS2# sh int br > tftp://10.73.54.194
    Trying to connect to tftp server......
    Connection to server Established. Copying Started.....
    TFTP put operation failed:Access violation
    Error 0x40870004 while copying tftp://10.73.54.194/
    MDS2# copy bootflash:cpu_logfile tftp://10.73.54.194
    Trying to connect to tftp server......
    Connection to server Established. Copying Started.....
    |
    TFTP put operation was successful
    MDS2#
    ck-ci9216-001# sho ver | inc system
      system:    version 3.2(1a)
      system image file is:    bootflash:/m9200-ek9-mz.3.2.1a.bin
      system compile time:     9/25/2007 18:00:00 [10/06/2007 06:46:51]
    ck-ci9216-001# sh int br > tftp://10.73.54.194
    Trying to connect to tftp server......
    |
    TFTP put operation was successful

    Please check with new version of TFTPD 32 server. The error may be due to older version of TFPT server, the new version available solved this error. Files are getting uploaded with no issues.
    1. Download tftpd32b.zip from:
    http://tftpd32.jounin.net/tftpd32_download.html
    2. Copy the tftpd32b.zip file into an empty directory and extract it.
    3. Copy the file you want to transver into the directory containing tftpd32.exe.
    4. Run tftpd32.exe from that directory. The "Base Directory" field should show the path to the directory containing the file you want to transfer.
    At this point, the tftpserver is ready to begin serving files. As devices request files, the main tftpd32 window will log the requests.
    Best Regards...

  • Issues with using the system restore discs from Acer

    I am trying to restore an Acer laptop using the restore CD's that I ordered from Acer. Everything works fine until the restore gets to 93% copy progress and 24% copying progress and then the restore locks up. I have tried it 3-4 times with the same issue happening each time. Any ideas?
    Thank you,
    Richard
    [edited for privacy-please do not post personal or unique information such as but not limited to full names, email addresses, phone numbers, serial numbers, etc.]

    I did try the reinstall process using the ALT+TAB keys and this did not fix the issue. The system is locking in the same place of the restore every time. I feel this may be an issue with the hard drive and therefore I feel it will be necessary to replace it. Does this sound like and accurate assumption?

  • Issue with using the archive/deploy feature in CF10

    Hello, I have created a backup archive using the archive wizard under the packaging and deployment wizard.   This archive is from the parent instance and shows everything that I need to backup in the summary window properly, when I try to deploy this archive to a child instance I notice a few of the settings do not migrate over.   For example I did a deploy and noticed the mail, web services settings did not migrate over properly, they don't even show up in the summary window pre deploy.    If I try to manually add those options in the child instance I receive a generic error and it kicks me back out to the CF Admin login window.   Anyone run into an issue like this before?

    So I tried to create an archive file where only the mail settings were selected and named it mail.car from the parent instance.   The migration windows shows only mail settings have been chosen but when I chose to migrate that archive back into a child instance it still fails to carry over the mail server.   This is odd because in the deploy summary window it does show mail settings is being migrated yet the setting never actually does show up correctly.

  • How to resolve the issue with Finder: "The last time you opened finder, it unexpectedly quit when reopening Windows"

    For anyone who is struggling with this issue that simply will not go away, please try:
    1. Fist turn off the mac
    2. Turn on the mac while holding the shift key (safe mode)
    3. Once all logged in click on Finder at the bottom of your screen
    4. Click on Go 5 steps to the right of the Apple logo
    5. Hold the Alt key and click on Library
    6. Open the Preferences folder
    7. Drag 'com.apple.Finder.plist' to yourDesktop
    7. Restart the mac
    That should hopefully resolve it, if not place the plist file on your Desktop back to its original location. Thank you!

    Do a backup.
    Quit the application.
    Go to Finder and select your user/home folder. With that Finder window as the front window, either select Finder/View/Show View options or go command - J.  When the View options opens, check ’Show Library Folder’. That should make your user library folder visible in your user/home folder.  Select Library. Then go to Preferences/com.apple.mail.plist. Move the .plist to your desktop.
    Restart, open the application and test. If it works okay, delete the plist from the desktop.
    If the application is the same, return the .plist to where you got it from, overwriting the newer one.
    Thanks to leonie for some information contained in this.

  • Decode with multiple column sub query

    Dear's
    What is the wrong with the query
    select * from common_master
    where
    (company_code,lpad(rtrim(ltrim(bu_code)),12,' ')) IN
    decode ('ADMIN','ADMIN',(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from common_master )
    ,(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from user_system_privs) )
    The error message as
    Error starting at line 16 in command:
    select * from common_master
    where
    (company_code,lpad(rtrim(ltrim(bu_code)),12,' ')) IN
    decode ('ADMIN','ADMIN',(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from common_master )
    ,(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from user_system_privs) )
    Error at Command Line:18 Column:53
    Error report:
    SQL Error: ORA-00920: invalid relational operator
    00920. 00000 - "invalid relational operator"
    *Cause:   
    *Action:
    Dennis

    You can club the columns in where clause and in decode
    like
    select * from common_master
    where
    (company_code || lpad(rtrim(ltrim(bu_code)) || to_char(12) ||' ') IN
    ( select decode ('ADMIN','ADMIN',company_code || lpad(rtrim(ltrim(bu_code)) || to_char(12) || ' ') from common_master ),
    ,company_code || lpad(rtrim(ltrim(bu_code)) || to_char(12) ||' ') from user_system_privs) )
    HTH,
    ~Yogesh

  • Sub query in where clause

    I have the following code which keeps throwing an error:
    select distinct game_code, count(player_id)
    from customer_data.cd_nhl_gm_tender_stats t
    where 
    (select distinct player_id
    from customer_data.cd_nhl_gm_tender_stats
    where season_id = 200818)
    group by game_code, player_id
    having count(player_id) > 1Error states that there's a missing expression right before the group by, any thoughts?
    The subquery is basically used to find a unique player_id value, (so there's no duplicates rows in the result set.)
    Sample data;
    customer_data.cd_nhl_gm_tender_stats t
    Game_code player_id
    88484           545454
    88484           545454
    88484           545454There's obviously other columns in the table above, but ultimatly there is mutliple rows for each game.
    I'm just trying to return each game_code where more then one player_id is found.

    Michaels2 i'm not sure your code is doing quite what i need
    select   *
      from   (select   t.*,
                       count (distinct player_id) over (partition by game_code) cnt
                from   cd_nhl_gm_tender_stats t where season_id = 200818)
    where   cnt > 1The subquery in the from clause is just selecting every game_code where season_id 200818 and then you add a where clause where cnt > 1 in the main query(whcih doesn't accomplish what I really wanted). What I need is the count of distinct player_id where season_id = 200818 AND cnt of (distinct player_id) over (partition by game_code) cnt > 2**. The issue i'm having is, that i'm not quite sure how to format the code to get these results.
    To clairfy what i need one more time ( i didn't explain things well in my original post)...
    I want each game_code where a player_id count is greather then two. And as stated earlier the gm_tender_stats table has numerous entries with the same player_id for the same_game code, which is why this makes writing this query a little more difficult.
    Edited by: user652714 on May 11, 2009 7:52 AM

  • Issue with using the Mercury Playback Engine in Hardware Accel mode on the new Mac Pro

    So I have seen many people with this same issue but different variations... I have a late 2013 mac pro with the D300 video card. when i am editing a project and turn on hardware acceleration (open CL) everything works fine, its super fast i can export etc... BUT when I close the project and try to re open it premiere locks up every time, not getting past the opening screen. I then have to open the project on my macbook pro and go in to settings and turn off the hardware acceleration to software only, then re save the project file. THEN i can open the project back on my Mac Pro...

    Macbook Pros do not have separate graphics cards — they are soldered onto the logic board and not interchangeable or replaceable. You can order the cards that are offered, no others. I have no idea whether or not Premiere likes any of them.

  • My opatical equipment measures the brightness with using the parallel port.

    How can I receive that data ? Plz...send me ur advices through e-mail.
    My address : [email protected]

    Hello,
    You should probably be a bit more specific in your problem description. Please post your question in the software category that pertains to your application. For instance, if you are using LabVIEW to communicate with your parallel port, you may want to post your question in one of the LabVIEW categories.
    Good luck with your application.
    Sincerely,
    Darren Nattinger
    Applications Engineer
    National Instruments
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Are there any know issues with using multiple (2) apple tv's in the same household??

    I'm thinking of getting a second Apple TV. Are there any known issues with using multiple (2) apple tv's in the same household? Thank you in advance.

    No, shouldn't have any problems

  • Issues with using aftermarket 2G chargers with the iphone

    I was using my iphone 3GS last night and battery was over 90% I had just gotten done shooting some video and I was on my PC trying to figure what I needed to do to upload the video to YouTube. I pulled iPhone out of my pocket it was completely dead. I tried soft reset and hard reset with no luck. I thought maybe I had misread how charged the battery was and it had just died. When I got home I plugged it and let it charge overnight on an aftermarket charger. When I woke up this morning same thing. No power, no response( I tried plugging it into the wall and into the USB port of my laptop) I also tried soft reset and hard reset again this morning still no luck. I had been using an after market home charger that I had purchased with my original iPhone 2g. It seemed to work with no problems on the new phone and I had used it everynight for the last week or so.
    As a last resort I put my iPhone in a new case-mate charger/holster I had just purchased and finally it gives me the battery charging icon. My conclusion is that the after market charge I have will work OK for charging a low battery to full again but if the phone is completely dead then maybe only an original charger will work. The problem is I have USB cables and home charges and car chargers from my iPhone 2g and my iPod touch and I assumed they would all work and were interchangeable but now I am not so sure. I am also stumpped as to how my battery could say 90% and 2 hours latter the phone is compelty dead. The only things I had done was turn on location services ( I was messing around with an app I downloaded (Zillow) and used the camera for less than 5 minutes and made 2-3 calls. Maybe the case-mate holster charger I had used ealier in the day had given a false full charge, I am not really sure at this point I am still trying to sort out the issue.

    Apple changed the pin configuration with the 3G on phones ,ipod and itouch back in 2008
    They removed the firewire charge option new kit is now not compatible with older
    options that charge
    ie 3G or 3Gs for that matter will not charge on original Bose Sound dock or Apple
    docks for starters

  • I have bought a used macbook, to bad i do not have the admin password. is there any way to bypass this issue with out the Mac OS X disk? (without loosing my obtained files?)

    i have bought a used macbook, to bad i do not have the admin password. is there any way to bypass this issue with out the Mac OS X disk? (without loosing my obtained files?)   I NEED HELP BADLY PLEASE....

    What version of the Mac OS X are you running. Go to the Apple in the upper left corner and select About This Mac and post the version.

  • I have been having a issue with getting the colors on my monitor to match the colors fro my print lab. I now have the monitor calibrated to match the prints but when I open elements it doesn't use the same colors. If i have it use the calibrated profile b

    I have been having a issue with getting the colors on my monitor to match the colors fro my print lab. I now have the monitor calibrated to match the prints but when I open elements it doesn't use the same colors. If i have it use the calibrated profile by changing the color management settings, the color picker no longer shows true white or black. How do I get elements 12 to honor the new calibrated settings?

    Ok so I've done what you said and this is what it's come back ....
    I don't know that these are the errors , but they're the things which don't look right ...
    Throughout the shut down there is a recurring line ;
    It says ;
    Com.apple.launchd 1 0x100600e70.anonymous.unmount 301 PID still valid
    Then there are 2 more which I think are related ;
    Com.apple.securityd 29 PID job has I overstayed its welcome , forcing removal.
    Then the same with fseventd 48 and diskarbitrationd 13
    Oh and on Launchd1 : System : stray anonymous job at shut down : PID 301 PPID13 PGID 13 unmount...
    Then the last process says "about to call: reboot (RB_AUTOBOOT).
    Continuing...
    And stops ...
    Hope this means something to you ... Thanks again for your help so far :-)

  • Just wondering what Apple's stand is on the issue with a flickering and a dark area appearing on imac 27"screen - forums seem to indicate this is not uncommon - and happens through normal use - so should be subject to repair (Sale of Goods Act - 6 years)

    Just wondering what Apple's stand is on the issue with a flickering and a dark area appearing on imac 27"screen - forums seem to indicate this is not uncommon - and happens through normal use - so should be subject to repair (Sale of Goods Act - ie 6 year warranty)

    We are just users like yourself.  If Apple has stated publicly about the problems you mentioned, it will be listed on their website and/or in one of their Knowledge Base Articles.
    I have a 27" & do not suffer from such a problem.  You should keep in mind that these are technical support forums. Generally, the only people posting here are those with problems. The thousands/millions without problems don't ever come here. 
    Think of these forums as a hospital emergency room. 

  • HI. ... Anyone know of any issues with using Logic Pro music software with Mountain lion OS.. I have heard rumours in the past is that all sorted now?

    HI. ...
    Anyone know of any issues with using Logic Pro music software with Mountain lion OS..
    I have heard rumours in the past is that all sorted now?

    At least Logic Pro 9 and Logic Pro X work correctly in Mountain Lion. Furthermore, Logic Pro X requires the latest OS X Mountain Lion version

Maybe you are looking for

  • How to send a video to apple support

    Before I contact apple support or while I am communicating with apple support, I would like to send a video of my (problem) screen because it is easier to see what is going on than it is to explain.

  • Configuration assistant "Oracle Database Configuration Assistant" failed

    I install oracle 10g on HP UX 11.23. I got this error : hecking for PHSS_33278; found Not found.     Failed <<<< Checking for PHSS_33279; found Not found.     Failed <<<< Checking for PHSS_33277; found Not found.     Failed <<<< Checking for PHSS_332

  • Report Designer - Asynchronous vs Synchronous

    Greetings fellow Oracle groupies, I have been working with BI Publisher EE for the past few months and would like to hear the community's thoughts around the Asynchronous mode option that is available when designing a report. The 'Report Designer's G

  • Can't see my videos in iTunes?? how to remove them??

    hey all. i have a bunch of 'coverted' mp4s on my iPod. they play fine from there. i'm trying to delete them off iPod..but cannot see any videos in iTunes! -Ipod->movies and theres nothing. -Music lists all my music... no videos? anyone help?

  • Change in Work Schedule Rule

    Hello I need one help I have changed the WSR for a specific personnel area changing the time of the working hours, so now after changing the settings do I need to generate WSR Manually if yes do i need to create or change the existing one When I trie