# Inner join by comparing column values

**URL:** <https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [September 5, 2023, 3:23am UTC](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528 "2023-09-05T03:23:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandy45](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Post date:** [September 5, 2023, 3:23am UTC](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528/1 "2023-09-05T03:23:55Z")

</div>

I just wanted to check if we can do inner join and fetch result of matching rows by comparing column values of two data frames.

Currently I’ve tried below code and getting error “ArgumentError: All elements of `on` argument to `join` must be Symbol or Pair{Symbol, Symbol}.”

```julia

innerjoin(df2, df1, on = [:DPRT_CD, :timeline => (>=, <=)], makeunique = true)

df2

3×5 DataFrame
 Row │ c d DPRT_TML DPRT_CD timeline
     │ Int64 String Int64 String Int64
─────┼────────────────────────────────────────────────────
   1 │ 1 f 786 ABC 50
   2 │ 2 g 846 DEF 50
   3 │ 3 h 915 ABC 50

df1

5×5 DataFrame
 Row │ DPRT_CD timeID timeStart timeEnd timeline
     │ String Int64 Int64 Int64 Int64
─────┼───────────────────────────────────────────────────────────────
   1 │ ABC 1 0 59 50
   2 │ ABC 2 60 119 50
   3 │ ABC 3 120 179 50
   4 │ ABC 4 180 239 50
   5 │ ABC 5 240 299 50

```

---

<div class="post-metadata">

**Author:** ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Post date:** [September 5, 2023, 4:16am UTC](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528/2 "2023-09-05T04:16:09Z")

</div>

I’m not sure if I’m understanding the question. If you want to make a join matching rows where both `DPRT_CD` and `timeline` are equal in each dataframe, you can do:

`innerjoin(df2, df1, on = [:DPRT_CD, :timeline], makeunique = true)`

Then, the matching would be when rows in one dataframe have the same `:DPRT_CD` and `:timeline` as the other dataframe.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [September 5, 2023, 6:30am UTC](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528/3 "2023-09-05T06:30:31Z")

</div>

I guess you want to perform a join using a condition. Use [Readme · FlexiJoins.jl](https://docs.juliahub.com/FlexiJoins/FdNoY/0.1.33/) to achieve this. In the future we might add it to DataFrames.jl

---

<div class="post-metadata">

**Author:** ![Sandy45](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Post date:** [September 5, 2023, 1:25pm UTC](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528/4 "2023-09-05T13:25:46Z")

</div>

@bkamins Yes, you are correct this is what I am looking for. Thanks for shedding lights on it.
