# Keeping the previous key ordering when joining two dataframes

**URL:** <https://discourse.julialang.org/t/keeping-the-previous-key-ordering-when-joining-two-dataframes/3097>\
**Category:** New to Julia\
**Created:** [April 7, 2017, 2:07am UTC](https://discourse.julialang.org/t/keeping-the-previous-key-ordering-when-joining-two-dataframes/3097 "2017-04-07T02:07:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [April 7, 2017, 2:07am UTC](https://discourse.julialang.org/t/keeping-the-previous-key-ordering-when-joining-two-dataframes/3097/1 "2017-04-07T02:07:26Z")

</div>

Hello,

When joining the following dataframes,  
`name = DataFrame(Order = [400, 3, 1], Name = ["John Doe", "Jane Doe", "Joe Blogs"])`  
`job = DataFrame(Order = [400, 2, 1], Job = ["Lawyer", "Doctor", "Farmer"])`  
`namejob = join(name, job, on = :Order)`

one gets:  
`Row Order Name Job`  
`1 1 "Joe Blogs"	"Farmer"`  
`2	400 "John Doe"	"Layer"`

However I would like to get instead:  
`Row	Order Name Job`  
`1	400 "John Doe"	"Layer"`  
`2 1 "Joe Blogs"	"Farmer"`

Is it possible to join two dataframes and keep the initial ordering without re-sorting or incurring some other overhead?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [April 7, 2017, 7:08am UTC](https://discourse.julialang.org/t/keeping-the-previous-key-ordering-when-joining-two-dataframes/3097/2 "2017-04-07T07:08:02Z")

</div>

I guess with ‘initial ordering’ you mean initial ordering of the left DataFrame (in this case `name`)? (a join will almost always include some sorting). You can achieve that by adding the keyword `kind = :left`. It will not do exactly what you want, though, as that will keep the full left DataFrame, including `Jane Doe`). You can use `completecases` to weed out rows like `Jane Doe`, but AFAICS there is no way to do what you want in a single operation.
