Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help with join tables with exclusion data.

Hi,

I need join two tables, similar to outer join, but I need add into the first table only values of the second table that not exist on first table. Validating only the key field.

How is that done..

1 Solution

Accepted Solutions
yduval75
Partner - Creator III
Partner - Creator III

You have to use the concatenate function in addition to not exits function as said peshu82

If you have the same fields and the same number of fields between table 1 and table 2, the concatenation is automatic.

Concatenate (Table1)

LOAD

----------

From Table2

where not exists (key);

View solution in original post

9 Replies
peschu123
Partner - Creator III
Partner - Creator III

Hi,

a few more data or example files would be great...

But take a look at exists() function

You can use it like

LOAD ...

FROM/RESIDENT ... WHERE NOT EXISTS(key);

yduval75
Partner - Creator III
Partner - Creator III

You have to use the concatenate function in addition to not exits function as said peshu82

If you have the same fields and the same number of fields between table 1 and table 2, the concatenation is automatic.

Concatenate (Table1)

LOAD

----------

From Table2

where not exists (key);

Not applicable
Author

With Not Exists() Function: Show error Field not found <Key>

The name of the fields is the same on the tables 1 and 2.

Where I am going wrong.

Example:

Table 1

Key, A

1,10

2,10

3,10

Table 2

Key, A

1,9

4,9

Expected Result

Key, A

1,10

2,10

3,10

4,9

Result With Outer Join OR Concatenate

Key, A

1,10

1,9

2,10

3,10

4,9

I use this code.

  [Table1]:

  LOAD

  Key,

  A,

  B,

  FROM

  Table1.QVD;

  [Table2]:

  Concatenate(Table1)

  LOAD

  Key,

  A,

  B,

  FROM

  Table2.QVD

  WHERE

  NOT EXISTS(Key);

yduval75
Partner - Creator III
Partner - Creator III

I tried with your example.

I get the expected result

I have attached my qvw

Not applicable
Author

Yoann, look my real code, but don't worked.

Will be the name of field. I am renaming all fields.

  [Preco_Medio_Venda_Tmp]:

  LOAD

  left([Faturamento - Código Produto],5) & ' - ' & [Faturamento - Mercado] AS CHAVE,

  left([Faturamento - Código Produto],5) AS [Preço Médio Venda - Referencia],

  [Faturamento - Mercado] AS [Preço Médio Venda - Mercado],

  Sum([Faturamento - Valor Líquido Total] - [Faturamento - Valor ICMS Substituição] - [Faturamento - Valor IPI])/Sum([Faturamento - Quantidade]) AS [Preço Médio Venda - Valor Venda Médio]

  RESIDENT

  [Fato Faturamento]

  WHERE

  [Faturamento - Ano] = $(ANO_BASE)

  AND Num(Month([Faturamento - Data Emissão])) = Num($(MES_BASE))

  AND [Faturamento - Grupo CFOP] = 'VENDA'

  GROUP BY

  left([Faturamento - Código Produto],5),

  [Faturamento - Mercado];

  LOAD

  left([Faturamento - Código Produto],5) & ' - ' & [Faturamento - Mercado] AS CHAVE,

  left([Faturamento - Código Produto],5) AS [Preço Médio Venda - Referencia],

  [Faturamento - Mercado] AS [Preço Médio Venda - Mercado],

  Sum([Faturamento - Valor Líquido Total] - [Faturamento - Valor ICMS Substituição] - [Faturamento - Valor IPI])/Sum([Faturamento - Quantidade]) AS [Preço Médio Venda - Valor Venda Médio]

  RESIDENT

  [Fato Faturamento]

  WHERE

  NOT EXISTS(CHAVE)

  AND [Faturamento - Ano] = $(ANO_BASE)

  AND Num(Month([Faturamento - Data Emissão])) = Num($(MES_BASE) - 1)

  AND [Faturamento - Grupo CFOP] = 'VENDA'

  GROUP BY

  left([Faturamento - Código Produto],5),

  [Faturamento - Mercado];

yduval75
Partner - Creator III
Partner - Creator III

You have to use


NOT EXISTS (CHAVE, left([Faturamento - Código Produto],5) & ' - ' & [Faturamento - Mercado])


instead of

NOT EXISTS (CHAVE)

Not applicable
Author

Now it's worked, but don't load data of the second table.

yduval75
Partner - Creator III
Partner - Creator III

For the test, just load the second table and check that you have different values

Not applicable
Author

Yoann,

Worked perfectly now, I was loaded null values on the first table.

Thanks for the help.