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

subtraction of two tables

I think there is an easy way to solve this, but by the moment I couldn't find it, I tried with combinations of JOIN, but I think this is not the correct way to solve it.

Here is my challenge :

I have two tables : Table1 and Table2.

Table1:

error loading image

Table2:

error loading image

I can't use the JOINS function (left, right, inner, outer), because they put in the result table all the possible combinations because of 'A' has the same value in all the rows.

My wrong result and I don't know how to handle is this :

error loading image

And my desired result is to get all the records on Table1 that they are not in Table2. It would be :

A , B

10 , 300

10, 400

10, 500

10, 600

10, 700

10, 800

10, 900

10, 1000

I've attached a file to clarify what I'm trying to say.

Thank you very much in advance.

Regards

1 Solution

Accepted Solutions
syed_muzammil
Partner - Creator II
Partner - Creator II

Hi,

You can load the Table2 frist and then load Table1 with the Where Not Exists function. This will load only those records not present in Table2.

Regards,

Syed.

View solution in original post

5 Replies
syed_muzammil
Partner - Creator II
Partner - Creator II

Hi,

You can load the Table2 frist and then load Table1 with the Where Not Exists function. This will load only those records not present in Table2.

Regards,

Syed.

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Thanks for your quick reply Syed.

I'm sorry because I don't understand you very well.

How can I do in this case the "not exists function?", because the values of A are always the same, and B and C are diferent columns. So I don't know how can I put a NOT EXISTS here.

Could you be more specific?

Many thanks anyway.

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Ok, finally I found the solution thanks to Syed.

First I have to Load the subtraction Table (the table I want to subtract from a Base table) :

SubtractionTable:

load * inline [

A, B

10, 100

10 , 500

];

Then, I load the Base Table :

BaseTable:

load * inline [

A , C

10 , 100

10 , 200

10 , 300

10 , 400

10 , 500

10 , 600

10 , 700

10 , 800

10 , 900

10 , 1000


] where not exists(B,C);

And you're gonna have the desired result : all the records of the Base Table which they aren't in the Subtraction Table.

I've attached the file with the desired result. It could be useful for others.

nathanfurby
Specialist
Specialist

If you want to exclude all similar values in columns B and C without taking into account column A then you can do it in the way suggested.

If you only want to exclude values where both columns A and B match columns A and C then I think you would need to include some kind of 'key' check. I have attached an example if you are interested.

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Many thanks Nathan for your contribution, you make more complete the previous solution.

In my case, the previous solution was fine, but you're right, if you want to check it more clearly, making a unique key with both values, I'm pretty sure you can avoid future problems doing that.

See you around.

Thanks.