Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to fetch the unique records in two differnt tables

table1:                                                   table2:

bar            value                                    bar            value

1                 raj                                         1              null

2                 null                                        3             null

4                 ren                                          4            null

5                null                                          6             null

I want merge this 2 tables and fetch the unique  values..

excepted output:

bar         value

2              null

3              null

5               null

6              null

6 Replies
puttemans
Specialist
Specialist

Hi there,

This seems not to be doable with a join or keep function. Therefore, an alternative is to work in steps :

- first I'd join both tables

- then create a mapping table, that counts the number of occurencies of 'bar'

- then apply the mapping on the initial table

- and to end, reload this mapped table, only taking into consideration where the mapping variable  = 1

Regards,

Johan

Not applicable
Author

Hi johan,

Thank you for replay....I can't understand wat u r saying..

can u explain briefly with script...

regards

ravi.

puttemans
Specialist
Specialist

Hello Ravi,

That would look like :

100:

LOAD

     bar,

     value

FROM table 1

concatenate

    

LOAD

     bar,

     value

FROM table2

Map_count:

MAPPING LOAD

     bar,

     COUNT(bar)

RESIDENT 100

group by bar;

200:

LOAD *

     Applymap('Map_count', bar) as count

RESIDENT 100;

DROP TABLE 100;

300:

LOAD *

RESIDENT 200

WHERE count = 1;

DROP TABLE 200;

Regards,

Johan

Not applicable
Author

Thanks Johan,

but it's not working properly.

Not applicable
Author

correct answer:

tabl1:

load bar,

value from tabl1 where not exists(bar);

concatinate

load  bar,

value from table2;

Not applicable
Author

Hi ALL,

in above requirement I want fectch only duplicate values.

excepted output:

bar   value

1       raj

1       null

4       ren

4       null