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

Update field of a resident table depending on values of another table

Hi,

Due to my inexperience I don't know how to solve this apparently simple problem.

I've loaded a table with a id, some data and a flag 0/1, with default value 0


Employees1:

LOAD id,

  ...

  0 AS flag

FROM [..];

idflag
A0
B0
C0
D0

Also, I've another table 'Employees2' with the same ids as 'Employees1'

Employees2:

LOAD id,

  ...

FROM [..];

id
A
C


The problem is that I need to update the field 'flag' of 'Employees1' in order to set a value of 1 for the records whose ids are present in 'Employees2'. In the example, this is the final outcome desired:

idflag
A1
B0
C1
D0

I'm considering looping 'Employees1', checking if each id exists in 'Employees2' and updating the flag if it's the case, but I don't konw if this is possible (in special the update part) or if this is the correct approach.

Thanks in advance,

1 Solution

Accepted Solutions
ahaahaaha
Partner - Master
Partner - Master

Hi,

May be like this?

Table1:

LOAD*Inline

[id

A

B

C

D

];

Left Join

Table2:

LOAD*Inline

[id, Flag

A, 1

C, 1

];

In table NULL value change to zero.

Result

1.jpg

View solution in original post

3 Replies
ahaahaaha
Partner - Master
Partner - Master

Hi,

May be like this?

Table1:

LOAD*Inline

[id

A

B

C

D

];

Left Join

Table2:

LOAD*Inline

[id, Flag

A, 1

C, 1

];

In table NULL value change to zero.

Result

1.jpg

Not applicable
Author

Yes, it's correct, it can be done easily with a left join. Tanks!

Shalom_Daniel
Contributor II
Contributor II

Hi,

This solution will work perfectly when there is no data in Table 1, however can you please tell how will you update if there exist values for different columns and you have to update more than one columns.