# Execute Insert\_all from a select

**URL:** <https://forum.elixirforum.com/t/execute-insert-all-from-a-select/15735>\
**Category:** Questions\
**Tags:** ecto, phoenix, ecto-query, insert\
**Created:** [August 10, 2018, 9:29am UTC](https://forum.elixirforum.com/t/execute-insert-all-from-a-select/15735 "2018-08-10T09:29:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![romaluca](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/romaluca/32/11213_2.png) [@romaluca](https://forum.elixirforum.com/u/romaluca)\
**Post date:** [August 10, 2018, 9:29am UTC](https://forum.elixirforum.com/t/execute-insert-all-from-a-select/15735/1 "2018-08-10T09:29:49Z")

</div>

I need insert some information of a table in another table.  
Is possible to do something like this code (that doesn’ t work) to execute only one query and not 2 separately?  
Thanks

```
followers = from u in User,
            select: %{user_id: u.id, topic_id: ^topic.id},
            inner_join: a in Activity, on: [user_id: u.id],
            where: a.contest_id == ^topic.contest_id
              and a.type == 1
          Repo.insert_all(TopicUser, followers)

```

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [August 13, 2018, 8:15pm UTC](https://forum.elixirforum.com/t/execute-insert-all-from-a-select/15735/2 "2018-08-13T20:15:21Z")

</div>

The question becomes, how would you do this in normal SQL?

Once shown there then it can be translated to Ecto (or if it is simple with little to no possible typing issues in the future then just keep it as SQL). 🙂
