Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Left Join with ON clause

Hi,

I have two tables with that structure:

Table1:

id | Numb | date |

Table2:

Numb | dateInit | dateEnd | Loc

I want to do a left join between this two tables ( Numb )  in order to add the Loc field to the Table1 when  date >= dateInit AND date <= dateEnd

in MYSQL :

SELECT tb1.id,tb1.Numb,tb1.date,tb2.Loc FROM Table1 as tb1
     
LEFT JOIN Table2 as tb2
            
ON tb1.Numb = tb2.Numb AND tb1.date >= tb2.dateInit AND tb1.date <= tb2.dateEnd


Thanks in advance

Albert

Labels (1)
6 Replies
vikasmahajan
MVP
MVP

What is a issue It seems this sql is ok

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
alexandros17
Partner - Champion III
Partner - Champion III

try this

SELECT tb1.id,tb1.Numb,tb1.date,tb2.Loc FROM Table1 as tb1
     
LEFT JOIN Table2 as tb2
            
ON tb1.Numb = tb2.Numb

WHERE

tb1.date >= tb2.dateInit AND tb1.date <= tb2.dateEnd

lironbaram
Partner - Master III
Partner - Master III

hi you should use interval match

i'll try to upload a demo later

prasad_dumbre
Partner - Creator
Partner - Creator

Not applicable
Author

Yes, i know the mYSQL sentenc is correct, but i want to do it on Qlikview Script.    

alexandros17
Partner - Champion III
Partner - Champion III

TMP_Table:

LOAD id,Numb,date FROM Table1

left join

LOAD Numb,| dateInit, dateEnd, Loc FROM Table2

MyTable:

noconcatenate

LOAD

     *

resident TMP_Table

where

date >= dateInit AND date <= dateEnd

Drop table TMP_Table;