Join Dataframes on different IDs within date range


I am trying to merge two datasets. I am using query (as in the code below), but I should merge on i.ticker NOT equals j.ticker. Basically, I should merge to a focal i.ticker all other j.tickers whose i.datestart<j.actdats<i.dateend. In SQL I would merge for i.ticker^=j.ticker (or i.ticker!=j.ticker) but I do not think this option is implemented in Query. I was able to solve the issue in SQLite but it is extremely slow, due to the size of the datasets. Any suggestion on how to implement a fast solution?

Thank you very much.

x = @from i in df1 begin
    @join j in lt on i.TICKER equals j.TICKER
    @select {i.ACTDATS,i.TICKER, j.TICKER}
    @where j.ACTDATS>i.dateStart && j.ACTDATS<i.dateEnd 
    @collect DataFrame

1 Like