?
Solved

PAYER_ID has both atributes

Posted on 2016-11-21
4
Medium Priority
?
62 Views
Last Modified: 2016-11-21
Hello expert,

Payers can be type Lab = 17006 and type Non_Injury_TPA = 17006.
Have drafted query that gives me PAYER_IDs that are both types,
copied herewith below.

By ordering by Payer_ ID it can be seen which Payers have both types
but there are 7k of them so a query is needed that lists only Payer
that have both types.

Tried using an AND clause and a couple of other attempts with no luck.

I think it may be a GROUP BY but not sure of the syntax.

Is there a query which will list only Payers that have PAYER_TYPE_CODE 17006
and 17007?

Thanks.

Allen in Dallas
 

SELECT PAYER_TYPE_ID,
  PAY.PAYER_ID,
  PAYER_NAME,
  PAYER_TYPE_CODE,
  PAY.LAST_UPDATE_USER,
  PAY.LAST_UPDATE_DATE,
  PAY.IS_DISABLED
FROM CCM.CCM_PAYER_TYPE PAT
join CCM_PAYER PAY on  PAY.PAYER_ID = pat.payer_id
where payer_type_code = 17006
or payer_type_code = 17007
order by PAY.PAYER_ID
0
Comment
Question by:Allen Pitts
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
johnsone earned 2000 total points
ID: 41896580
Assuming that I guess the correct table name, this should work.
SELECT payer_type_id, 
       PAY.payer_id, 
       payer_name, 
       payer_type_code, 
       PAY.last_update_user, 
       PAY.last_update_date, 
       PAY.is_disabled 
FROM   ccm.ccm_payer_type PAT 
       join ccm_payer PAY 
         ON PAY.payer_id = pat.payer_id 
WHERE  payer_type_code = 17006 
       AND EXISTS (SELECT 1 
                   FROM   ccm_payer pay2 
                   WHERE  pay.payer_id = pay2.payer_id 
                          AND pay2.payer_type_code = 17007) 
ORDER  BY PAY.payer_id 

Open in new window

If not, you will have to change the EXISTS subquery.
0
 

Author Closing Comment

by:Allen Pitts
ID: 41896650
Hello johnsone,

Works great. Did change

AND EXISTS (SELECT 1
                   FROM   ccm_payer_id pay2
to
AND EXISTS (SELECT 1
                   FROM   ccm_payer_type pay2

So a second WHERE condition is used to see if
 there is a payer_type_code = 17007 .
Simple and effective.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41896679
0
 
LVL 35

Expert Comment

by:johnsone
ID: 41896707
Sorry.  There was no table alias indicating which table it came from, had to guess.
0

Featured Post

Industry Leaders: 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

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…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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 set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

862 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