Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello all, I have a issue with left join in my load data script. I have 2 tables like those:
TABLE A
project | subproject |
taxes |
AA | 11 | 0,1 |
AA | 22 | 0,2 |
BB | - | 0,3 |
Project BB don't have subproject
TABLE B
project | subproject | sales |
AA | 11 | 4 |
AA | 22 | 5 |
BB | - | 2 |
I need join both tables for get this:
project | subproject | sales | taxes |
AA | 11 | 4 | 0,1 |
AA | 22 | 5 | 0,2 |
BB | - | 2 | 0,3 |
This is my script:
LEFT Join TABLE B
Load
project, subproject, taxes
Resident TABLE A;
DROP TABLE TABLE A;
And I get this:
project | subproject | sales | taxes |
AA | 11 | 4 | 0,1 |
AA | 22 | 5 | 0,2 |
BB | - | 2 | - |
No "taxes" join to the table for all "project" without "subproject".
Can anyone show me where is the error please?
Best regards
Thanks to all for yours ideas, Finally I did this:
IF (len(subproject)='0','NA',subproject) as subproject
Works Perfect!
Hello,
before your 2 tables you can write:
NullAsValue subproject;
I would suggest creating a composite key yourself for joining the tables
A:
Load project,subproject,project&'-'&subproject as KEYFIELD,taxes inline [
project,subproject,taxes
AA,11,0.1
AA,22,0.2
BB,,0.3
];
Left JOin (A)
Load project&'-'&subproject as KEYFIELD,sales inline [
project,subproject,sales
AA,11,4
AA,22,5
BB,,2
];
exit Script;
Thanks to all for yours ideas, Finally I did this:
IF (len(subproject)='0','NA',subproject) as subproject
Works Perfect!