Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have to overwrite existing data with the new one based on some specific field, how can we do that.
A:
Load * inline
[
Name,Age
A,21
B,22
]
B:
Load * inline
[
Name,Age
A,33
C,22
D,23
]
Final O/P
Name,Age
A,33
B,22
C,22
D,23
no change in order of load
A:
Load *, -rowno() as id inline
[
Name,Age
A,21
B,22
];
B:
Load *, rowno() as id inline [
Name,Age
A,33
C,22
D,23
];
left join (A)
load Name, max(id) as maxid
Resident A
group by Name;
Tmp: load Name, Age Resident A Where id = maxid;
DROP Table A;
RENAME Table Tmp to A;
maybe with a not exists starting from the last table
B:
Load * inline [
Name,Age
A,33
C,22
D,23
];
A:
Load * inline
[
Name,Age
A,21
B,22
]
Where not Exists(Name)
;
Yes, this would work but, in our case we can't change the order of load, since we are creating some variables based on previous load. Please suggest some other solution.
Hi navdeep,
Try like this:
A:
Load * inline
[
Name,Age
A,21
B,22
]
B:
Load * inline
[
Name,Age
A,33
C,22
D,23
]
Noconcatenate
c:
load
name,
max(Age) as Age
resident A
group by name;
Drop table A;
Regards
KC
Thanks Joythish,
It's just a demo app, in prod we have lot of duplicates and we don't want this operation only for max value :-). but nice catch, and as mentioned we can't change the order of load.
no change in order of load
A:
Load *, -rowno() as id inline
[
Name,Age
A,21
B,22
];
B:
Load *, rowno() as id inline [
Name,Age
A,33
C,22
D,23
];
left join (A)
load Name, max(id) as maxid
Resident A
group by Name;
Tmp: load Name, Age Resident A Where id = maxid;
DROP Table A;
RENAME Table Tmp to A;
This is how I would do it, but there are various ways ...
A:
Load *, 1 as LoadIndex inline
[
Name,Age
A,21
B,22
E,45
q,10
];
Load *, 2 as LoadIndex inline
[
Name,Age
A,33
C,22
D,23
E,13
Q,11
];
inner join (A)
Load Name, max(LoadIndex) as LoadIndex resident A group by Name;
flipside
Hi Navdeep,
Can you try this?
A:
Load * inline
[
Name,Age
A,21
B,22
];
B:
LOAD *,RowNo() as New;
Load * inline
[
Name,Age
A,33
C,22
D,23
];
Concatenate
LOAD * Resident A
Where not Exists(Name);
DROP Table A;
Cheers,
Naresh
Hi,
I am not able to replicate, could you please share the app.
We are not doing any operation on data of table B, could you please explain how it will work ?
Edited- Got it, thanks