Skip to content
Advertisement

Query to join DateTimestamp column with another Table with StartDate and EndDate

I have below table with 3 column. Lets say table1 with the following data

Another table with 4 columns, lets say table2 with following data

What I would like to achieve is check in Table2 for start_date and End_Date where typ_Id = 1 from Table1 where E_Date comes under in Table2 Start_Date and End_Date.

for ID 7390706, 7390681,7390680 the E_Date comes under the range in table2 Start_Date and End_Date where Typ_ID=3 and for ID 7390709 there is no Start_Date and End_Date exist so those rows has be excluded from the final result.

So the final table has to be like this.

I am still learning joins so any help will be appreciated.

http://sqlfiddle.com/#!18/6eb43

Advertisement

Answer

Try the following and here is the demo.

output:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement