Avatar of sam2929
sam2929

asked on 

to find non matching records

Hi,
i want to find the request id which has diffrent centre for same request id

request id   centre
1001          8214
1001
1001          8214


1002          601
1002
1002          701



so result should be null can be filtered

1002  601
1002  701
DB2

Avatar of undefined
Last Comment
Tomas Helgi Johannsson
Avatar of Member_2_2484401
Member_2_2484401
Flag of United States of America image

This will get you pretty close:


select requestId,
       centre,
       count(*)
  from deleteme
 where centre is not null
 group by requestId,
          centre
having count(*) = 1

REQUESTID          CENTRE     COUNT ( * )
    1,002             701               1
    1,002             601               1

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_2484401
Member_2_2484401
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Member_2_276102
Member_2_276102

The suggested approach would give the result shown as long as every mismatch resulted in exactly count(*)=1. It would include all requestId values that only appeared in single rows as well as those that had multiple rows but single occurrences of centre.

What version of DB2 are you running?

What result do you want if the data looks this way:

request id   centre
1001          8214
1001
1001          8214


1002          601
1002          601
1002
1002          701


1003          5701

Tom
         Hi!
This should give you what you need

select distinct requestId, centre,
from deleteme
where centre is not null

Regards,
   Tomas Helgi  
DB2
DB2

IBM DB2 is a family of relational database server products developed by IBM that have been extended to support object-relational features and non-relational structures like JSON and XML. There are three main products in the DB2 family: DB2 for Linux, UNIX and Windows (informally known as DB2 LUW), DB2 for z/OS (mainframe), and DB2 for i (formerly OS/400), plus a version for IBM's Virtual Storage Extended (VSE) operating system.

6K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo