Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Lisa2
Contributor
Contributor

Not Exist and Exist with Multiple Values

Hello, is there a way that I can combine NOT EXISTS, looking for a value in two columns, and EXISTS all in the same WHERE clause?  For example: I need to know, from Table A, which Items A AND Items B do not exist in Table B Items, BUT which Prefix A from Table A  exist in Table B Prefix.  In other words, from Table A, which Items of A and B DO NOT EXITS and Prefix A does EXISTS in Table B.  This is going in the LOAD scriptIf anyone could point me in the right direction.  Thanks!

Table A:

Items APrefix AItems BPrefix B
1653-4616536214-586214
1653-5616531856-251856
3256-9832568123-738123
8523-1485233254-943254
5648-8756482145-842145
7892-9278921125-441125
3152-3531524563-704563
7559-7875597823-467823
6352-7463525613-435613
7325-1973253152-203152

Table B:

ItemsPrefix
1653-561653
2145-842145
7559-787559
3152-203152

 

Results:

Items APrefix AItems BPrefix B
1653-4616536214-586214
3256-9832568123-738123
8523-1485233254-943254
7892-9278921125-441125
3152-3531524563-704563
6352-7463525613-435613
Labels (4)
1 Solution

Accepted Solutions
Taoufiq_Zarra

Hi,

with the logic explaine, in the result the line 

3256-9832568123-738123

must not exist PrefixA=3256 not exist in the TableB.

So, I propose :

Table_A:
load * inline [
ItemsA,	PrefixA,ItemsB,PrefixB
1653-46,1653,6214-58,6214
1653-56,1653,1856-25,1856
3256-98,3256,8123-73,8123
8523-14,8523,3254-94,3254
5648-87,5648,2145-84,2145
7892-92,7892,1125-44,1125
3152-35,3152,4563-70,4563
7559-78,7559,7823-46,7823
6352-74,6352,5613-43,5613
7325-19,7325,3152-20,3152
];

Table_B:

load * inline [
Items,Prefix
1653-56,1653
2145-84,2145
7559-78,7559
3152-20,3152
];

output:
NoConcatenate
LOAD * Resident Table_A WHERE Not EXISTS(Items,ItemsA) and Not EXISTS(Items,ItemsB) and EXISTS(Prefix,PrefixA)
;

DROP table Table_A,Table_B;

 

and the output :

Capture.PNG

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

1 Reply
Taoufiq_Zarra

Hi,

with the logic explaine, in the result the line 

3256-9832568123-738123

must not exist PrefixA=3256 not exist in the TableB.

So, I propose :

Table_A:
load * inline [
ItemsA,	PrefixA,ItemsB,PrefixB
1653-46,1653,6214-58,6214
1653-56,1653,1856-25,1856
3256-98,3256,8123-73,8123
8523-14,8523,3254-94,3254
5648-87,5648,2145-84,2145
7892-92,7892,1125-44,1125
3152-35,3152,4563-70,4563
7559-78,7559,7823-46,7823
6352-74,6352,5613-43,5613
7325-19,7325,3152-20,3152
];

Table_B:

load * inline [
Items,Prefix
1653-56,1653
2145-84,2145
7559-78,7559
3152-20,3152
];

output:
NoConcatenate
LOAD * Resident Table_A WHERE Not EXISTS(Items,ItemsA) and Not EXISTS(Items,ItemsB) and EXISTS(Prefix,PrefixA)
;

DROP table Table_A,Table_B;

 

and the output :

Capture.PNG

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉