Join 3 tables and insert their data into new table

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

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.
  1. I've already made the table
  2. I'm doing it in ignition
  3. Just once
  4. Yes
  5. Yes

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

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.)

1 Like

Tried this, it doesn't work

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?
1 Like

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

3 Likes

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

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

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