# Join Dataframes on different IDs within date range

**URL:** <https://discourse.julialang.org/t/join-dataframes-on-different-ids-within-date-range/36425>\
**Category:** New to Julia\
**Tags:** query, dataframes\
**Created:** [March 24, 2020, 10:06am UTC](https://discourse.julialang.org/t/join-dataframes-on-different-ids-within-date-range/36425 "2020-03-24T10:06:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mp-crypto](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mp-crypto](https://discourse.julialang.org/u/mp-crypto)\
**Post date:** [March 24, 2020, 10:06am UTC](https://discourse.julialang.org/t/join-dataframes-on-different-ids-within-date-range/36425/1 "2020-03-24T10:06:09Z")

</div>

Hello,

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.

```julia
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
end

```

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [October 4, 2020, 2:05am UTC](https://discourse.julialang.org/t/join-dataframes-on-different-ids-within-date-range/36425/2 "2020-10-04T02:05:42Z")

</div>

Have you solved this issue?
