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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Compare column values from two different tables

Hi All,

May I know the best way that i can compare 2 tables and produce the results as field Flag as Yes/No in the script not in straight table.

Table1:

LOAD * INLINE [

    key, col1, col2

    A, 10, 20

    B, xx, yy

    C, ab, bc

];

Table2:

LOAD * INLINE [

    key, colA, colB

    A, 10, 20

    B, sd, yy

    D, ab, gh

];

Thanks!

1 Solution

Accepted Solutions
maxgro
MVP
MVP

With non duplicated key

Table1:

LOAD * INLINE [

    key, col1, col2

    A, 10, 20

    B, xx, yy

    C, ab, bc

];

Table2:

LOAD * INLINE [

    key, colA, colB

    A, 10, 20

    B, sd, yy

    D, ab, gh

];

Check2Tables:

load key, col1 & '|' & col2 as field1 Resident Table1;

join (Check2Tables) load key, colA & '|' & colB as field2 Resident Table2;

Left Join (Check2Tables)

load key, field1=field2 as Flag

Resident Check2Tables;


1.png



View solution in original post

5 Replies
sunny_talwar

What exactly are you comparing here? Checking if the key exists in both table or some other comparison?

Not applicable
Author

Hi,

I want to check based on key field whether value for col1 same with colA.. If yes. it will show flag field as Yes.

jagan
Partner - Champion III
Partner - Champion III

Hi,

Try like this

Temp:

LOAD * INLINE [

    key, col1, col2

    A, 10, 20

    B, xx, yy

    C, ab, bc

];

JOIN

LOAD * INLINE [

    key, colA, colB

    A, 10, 20

    B, sd, yy

    D, ab, gh

];

Data:

LOAD

*,

If(col1 = colA, 1, 0) AS col1AndcolAMatchFlag,

If(col2 = colB, 1, 0) AS col2AndcolBMatchFlag,

If(col1 = colA AND col2 = colB, 1, 0) AS MatchFlag

RESIDENT Temp;

DROP TABLE Temp;

Regards,

jagan.

jagan
Partner - Champion III
Partner - Champion III

Hi,

Check this

Hi,

Try like this

Temp:

LOAD * INLINE [

    key, col1, col2

    A, 10, 20

    B, xx, yy

    C, ab, bc

];

JOIN

LOAD * INLINE [

    key, colA, colB

    A, 10, 20

    B, sd, yy

    D, ab, gh

];

Data:

LOAD

*,

If(col1 = colA, 'Yes', 'No') AS col1AndcolAMatchFlag

RESIDENT Temp;

DROP TABLE Temp;

Regards,

jagan.

maxgro
MVP
MVP

With non duplicated key

Table1:

LOAD * INLINE [

    key, col1, col2

    A, 10, 20

    B, xx, yy

    C, ab, bc

];

Table2:

LOAD * INLINE [

    key, colA, colB

    A, 10, 20

    B, sd, yy

    D, ab, gh

];

Check2Tables:

load key, col1 & '|' & col2 as field1 Resident Table1;

join (Check2Tables) load key, colA & '|' & colB as field2 Resident Table2;

Left Join (Check2Tables)

load key, field1=field2 as Flag

Resident Check2Tables;


1.png