# Join 3 tables and insert their data into new table

**URL:** <https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069>\
**Category:** Ignition\
**Created:** [October 5, 2023, 12:43pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069 "2023-10-05T12:43:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christy\_Jean](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Christy\_Jean](https://forum.inductiveautomation.com/u/Christy_Jean)\
**Post date:** [October 5, 2023, 12:43pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/1 "2023-10-05T12:43:52Z")

</div>

I have 3 tables: table1 (bar, change, kit, lot, part), table2 (order, start date), table3 (end date)  
I want to join them and then insert those values into table4 (bar, change, duplicate, kit, lot, part, order, start date, end date)

I have no issue joining the 3 tables, it's the inserting into the new table I can't seem to figure out

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 5, 2023, 1:15pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/2 "2023-10-05T13:15:04Z")

</div>

How far have you got?

1. Have you created the new table?
2. Can you do this with your database management tool or are you trying to do it in Ignition?
3. Is this a once-off task or will you need to do it multiple times?
4. Are you stuck with the INSERT query?
5. Are you aware that you could use the Ignition Named Query tool to execute some one-off code using the Authoring and Testing tabs.

---

<div class="post-metadata">

**Author:** ![Christy\_Jean](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Christy\_Jean](https://forum.inductiveautomation.com/u/Christy_Jean)\
**Post date:** [October 5, 2023, 1:24pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/3 "2023-10-05T13:24:04Z")

</div>

1. I've already made the table
2. I'm doing it in ignition
3. Just once
4. Yes
5. Yes

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 5, 2023, 1:28pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/4 "2023-10-05T13:28:38Z")

</div>

The general SQL form for this sort of thing looks like this:

```auto
INSERT INTO "someTable" ("someColumn1", "anotherColumn")
SELECT someExprFor1, anotherExprFor2
FROM ....

```

In other words, just replace the `VALUES (...)` clause of a normal insert with the complete `SELECT ...` that has your joins. Just be sure that your select's output columns match up 1-for-1 with the target table columns that you've called out.

(Your database's documentation should show this.)

---

<div class="post-metadata">

**Author:** ![Christy\_Jean](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Christy\_Jean](https://forum.inductiveautomation.com/u/Christy_Jean)\
**Post date:** [October 5, 2023, 1:32pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/5 "2023-10-05T13:32:20Z")

</div>

Tried this, it doesn't work

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 5, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/6 "2023-10-05T13:42:54Z")

</div>

Christy, you need to be more specific in your posts.

1. What did you write.
2. What did you expect.
3. What did you get? Was there an error message? What was it?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 5, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/7 "2023-10-05T13:42:58Z")

</div>

> [@Christy\_Jean](#):
>
> it doesn't work

I don't know why it wouldn't work. You haven't shared enough detail to analyze any further. It **should** work.

Consider reading this classic, timeless, essay on **how** to ask for help, if you want to actually get help:

[http://www.catb.org/~esr/faqs/smart-questions.html](http://www.catb.org/~esr/faqs/smart-questions.html)

---

<div class="post-metadata">

**Author:** ![tmahaf](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaf/32/23492_2.png) [@tmahaf](https://forum.inductiveautomation.com/u/tmahaf)\
**Post date:** [October 5, 2023, 1:58pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/8 "2023-10-05T13:58:36Z")

</div>

Did you know that you can send screenshots to provide more info?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/0/10c505a701e02462a9b9bacac70ccba93263b039.png)

The "Text" output on queries can help past table results into help forums too!

---

<div class="post-metadata">

**Author:** ![Christy\_Jean](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Christy\_Jean](https://forum.inductiveautomation.com/u/Christy_Jean)\
**Post date:** [October 5, 2023, 2:11pm UTC](https://forum.inductiveautomation.com/t/join-3-tables-and-insert-their-data-into-new-table/80069/9 "2023-10-05T14:11:25Z")

</div>

I ended up not needing the date columns so I did  
`INSERT INTO table4 (bar, change, duplicate, kit, lot, part, order) SELECT bar, change, duplicate, kit, lot, part, (SELECT order FROM table2) FROM table1`  
and it worked
