Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
baliyan_vinay
Contributor III
Contributor III

Get Data when all records of query satisfy where condition

I've the following data table.

Primary IDSecond IDData
11AP
11BQ
11CR
11DS
22AQ
22BQ
33AS
33BQ
33CP

 

What I want to extract is Primary key where all records in data is 'Q'.  So only primary key 2 should return.

I am using SQL as well to extract this, what I was able to do is a match between count(data) of total records grouped by Primary Key and count(data) where data='Q' grouped by Primary Key.

Is there a better way to do it in QlikView or in SQL maybe? 

1 Solution

Accepted Solutions
Saravanan_Desingh

commQV03.PNGOne solution will be:

tab1:
LOAD [Primary ID], If(Concat(DISTINCT Data)='Q','Y') As Flag
Group By [Primary ID]
;
LOAD * INLINE [
    Primary ID, Second ID, Data
    1, 1A, P
    1, 1B, Q
    1, 1C, R
    1, 1D, S
    2, 2A, Q
    2, 2B, Q
    3, 3A, S
    3, 3B, Q
    3, 3C, P
];

View solution in original post

1 Reply
Saravanan_Desingh

commQV03.PNGOne solution will be:

tab1:
LOAD [Primary ID], If(Concat(DISTINCT Data)='Q','Y') As Flag
Group By [Primary ID]
;
LOAD * INLINE [
    Primary ID, Second ID, Data
    1, 1A, P
    1, 1B, Q
    1, 1C, R
    1, 1D, S
    2, 2A, Q
    2, 2B, Q
    3, 3A, S
    3, 3B, Q
    3, 3C, P
];