Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle query

Posted on 2014-04-15
8
Medium Priority
?
291 Views
Last Modified: 2014-04-30
select distinct d.drive_id,d.unit_id||'-'||chk_digit as unit_id,
               dn.donor_id,first_name,last_name,inter_code,
                     trunc(di.insert_date) as insert_date,
                 mc.description as blood_type      
  from donations_don d,
       donors_don dn,
         master_codes mc,
         units_lab u,
         donor_interdictions_don di
 where d.donor_id = dn.donor_id
   and di.donor_id = dn.donor_id
   and d.unit_id = u.unit_id
   and dn.blood_type = mc.udf1
   and procedure_code = 'WB'
   and mc.code_type = 'ABO'
   and (di.inter_code in ('HLAP','HLAN')
     or di.inter_code is null)
   and di.term_date is null       
   and d.coll_date between '14-apr-2014' and '14-apr-2014'
   and d.unit_id is not null
   and gender = 'F'
   and blood_type in (28,84)
 order by 1,2


But I have a donor that is not showing up on the report. This donor is not tested and we do not have an entry in the interdictions table. But I also want to show that donor that the donor was not tested.

 select donor_id,coll_date
 from donations_don
 where UNIT_ID = 'W039714879997'

DONOR_ID,       COLL_DATE
DN20322530,   4/14/2014

 
 select donor_id, inter_code, unit_id
 from donor_interdictions_don
 where donor_id = 'DN20322530'

No data found

But I need to show this donor on the report. I tried using  the below condition but could not get the right results.

and (di.inter_code in ('HLAP','HLAN')
     or di.inter_code is null
     or not exists (select donor_id from donor_interdictions_lab don
ab-donors.xls
0
Comment
Question by:anumoses
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1332 total points
ID: 40001957
>>This donor is not tested and we do not have an entry in the interdictions table. But I also want to show that donor that the donor was not tested.

Wouldn't this be an outer join between the necessary tables?

In the where clause, what columns designate 'tested'?

Add the (+) to the correct column in the where clause.

For an example check out the 'old syntax' here:
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6585774577187

I believe you are still on 9i?  I'm not sure if 9i allows for the ANSI syntax or not.
0
 
LVL 14

Assisted Solution

by:Alexander Eßer [Alex140181]
Alexander Eßer [Alex140181] earned 668 total points
ID: 40002003
I'm not sure if 9i allows for the ANSI syntax or not.
Why not?! It's ANSI, so it better should ;-)
One should really avoid using Oracle's native "(+)" joins, 'cause
 1. they're NOT portable to another RDBMS ;-)
 2. they're LIMITED considerung for instance left outer joins with more than one joined table

Cheers,
Alex
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40002005
>>Why not?!

Oracle didn't use to support the ANSI syntax.  I forget what release they started allowing it.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 6

Author Comment

by:anumoses
ID: 40002014
I tried using this query. But I am not getting the one donor that was not tested.

select distinct d.transaction_id,d.drive_id,d.unit_id||'-'||chk_digit as unit_id,
               dn.donor_id,first_name,last_name,null,
                     null,
                 mc.description as blood_type      
  from donations_don d,
       donors_don dn,
         master_codes mc,
         units_lab u
 where d.donor_id = dn.donor_id
   and d.unit_id = u.unit_id
   and dn.blood_type = mc.udf1
   and procedure_code = 'WB'
   and mc.code_type = 'ABO'
 and d.transaction_id not in (select di.transaction_id
               from donation_interdictions_don di
          where di.transaction_id = d.transaction_id)

   and d.coll_date between '14-apr-2014' and '14-apr-2014'
   and d.unit_id is not null
   and gender = 'F'
   and blood_type in (28,84)
   and d.donor_id ='DN20322530'
 order by 1,2
 
but when I run the below query

select distinct d.drive_id,d.unit_id||'-'||chk_digit as unit_id,
               dn.donor_id,first_name,last_name,null,
                     null,
                 mc.description as blood_type      
  from donations_don d,
       donors_don dn,
         master_codes mc,
         units_lab u
 where d.donor_id = dn.donor_id
   and d.unit_id = u.unit_id
   and dn.blood_type = mc.udf1
   and procedure_code = 'WB'
   and mc.code_type = 'ABO'
   and d.coll_date between '14-apr-2014' and '14-apr-2014'
   and d.unit_id is not null
   and gender = 'F'
   and blood_type in (28,84)
   and d.donor_id ='DN20322530'
 order by 1,2

DRIVE_ID,UNIT_ID,DONOR_ID,FIRST_NAME,LAST_NAME,NULL,NULL_1,BLOOD_TYPE

DRV2023865,W039714879997-8,DN20322530,SELENA,PRYSOCK,,,AB Pos

This is the donor that was not tested
0
 
LVL 41

Expert Comment

by:Sharath
ID: 40002143
What is your Oracle version?
0
 
LVL 6

Author Comment

by:anumoses
ID: 40002184
9i
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1332 total points
ID: 40002712
I'm still pretty sure this is a join issue not a sub select issue but I don;t know your tables or data.

Can you create a couple of sample tables with sample data that would show us what you are trying to accomplish?

Just like your previous questions, this will allow us to actually set up test cases to provide your expected results.

Note:  I'm not asking for all 4 tables that you are using with all columns.  Just two sample tables with a couple of columns each should do.

Just enough so if we produce your expected results, you can take our model and apply it back to your SQL.
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 40032254
thanks
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

610 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