TheConquistador
TheConquistador

Reputation: 3

Mysql multiple simultaneous insert into queries

I need to insert data into a set of columns in data_table (table 1) from alarm_status_log_table (table 2, the whole thing), and another set of data into data_table (table 1) from channel table (table 3, just name and description), thus completing data_table (table 1).

But the problem is, the name & description columns which I need to pass onto data_table must be on the same row as the alarm_id they correspond with. That alarm_id is the same as the channel_id from the channel table which happens to already have the name and description that I want to send to data_table.

Basically I want to say:

Insert (name, description) from channel(table 3) into data_table(name, description) where channel_id = alarm_id

How can I proceed?

enter image description here enter image description here

Upvotes: 0

Views: 147

Answers (2)

TheConquistador
TheConquistador

Reputation: 3

All i needed to do was to use a VIEW, since reordering data coming from two tables into a third table is quite tricky, here is the script i used to get the view i wanted:

SELECT channel.name, channel.description, alarm_status_log.* FROM data2desk.alarm_status_log LEFT JOIN data2desk.channel ON channel.channel_id=alarm_status_log.alarm_id

And it did the trick :)

final view

Upvotes: 0

Björn Karpenstein
Björn Karpenstein

Reputation: 221

It is possible to make an update JOIN like this:

UPDATE data_table a 
INNER JOIN table3 b ON a.alarm_id = b.channel_id
SET a.name=b.name, a.description=b.description

If you do not want to update, can you just join the tables? Maybe it would be better to create a joined view; this would avoid having redundant inconsistent data.

Upvotes: 1

Related Questions