Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help in join

Hi ,

i need to left join two tables based on a key and a condition, below is a sample table. i need to join based on key and the condition is only if Date>Start_Date and Date<End_Date

TABLE1:

keyDEVDate
1aacb5-05-15
1adcv1-05-15
2arfg8-05-15
2arre8-05-15
3acdf10-05-15


left join

TBALE2:

keyunitstart_dateend_date
1adff2-05-1510-05-15
1aff3-05-154-05-15
2abb7-05-1511-05-15
2akk7-05-1512-05-15
3abnn9-05-1511-05-15
1 Solution

Accepted Solutions
Not applicable
Author

Hi try this

tab1:

load

Key ,

DEV,

Date

from Table 1;

left jon

load

key,

unit,

start_date,

end_date

fro table2;

tab2:

load * Resident Tab1 where Date>Start_Date and Date<End_Date;

drop table tab1;

View solution in original post

5 Replies
ToniKautto
Employee
Employee

Do the left join first. Then extract the data that you want to have filtered, and inner join that with the data table.

Notice, that I changed in the format variables to make sure that the incoming dates are properly loaded as date values.

SET TimeFormat='hh:mm:ss';

SET DateFormat='DD-MM-YY';

SET TimestampFormat='DD-MM-YY hh:mm:ss[.fff]';

Table:

LOAD * Inline [

key, DEV, Date

1a, acb, 5-05-15

1a, dcv, 1-05-15

2a, rfg, 8-05-15

2a, rre, 8-05-15

3a, cdf, 10-05-15

];

left join

LOAD * Inline [

key, unit, start_date, end_date

1a, dff, 2-05-15, 10-05-15

1a, ff, 3-05-15, 4-05-15

2a, bb, 7-05-15, 11-05-15

2a, kk, 7-05-15, 12-05-15

3a, bnn, 9-05-15, 11-05-15

];

Inner Join

LOAD *

Resident Table

Where Date > start_date AND Date < end_date;

Not applicable
Author

Hi try this

tab1:

load

Key ,

DEV,

Date

from Table 1;

left jon

load

key,

unit,

start_date,

end_date

fro table2;

tab2:

load * Resident Tab1 where Date>Start_Date and Date<End_Date;

drop table tab1;

Not applicable
Author

thank you, this helped me

jonathandienst
Partner - Champion III
Partner - Champion III

TABLE1:

LOAD *

FROM Table1;

Left Join(TABLE1)

IntervalMatch(Date, key)

LOAD start_date, end_date, key

FROM Table2;

Left Join(TABLE1)

LOAD *

FROM Table2;

Because the dates for key 2a falls into 2 overlapping ranges you will get two rows back for each key 2a entry.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
ToniKautto
Employee
Employee

You're welcome!

Please remember to mark helpful answers as well as correct ones.

2015-04-30 13_28_19-Help _ Q.png