I am trying to get data from one row in a table into three rows in a temp table, so I can update the data based on values in a different, and I am wondering if there is a better approach than doing a UNION operation.
Here is the basic UNION syntax that gets the data from one row into the three rows I want:
(SELECT
0 as lead_id,
'RV' as lead_type,
'' as lead_serial,
rv_amplitude as amplitude,
rv_pulse_width as pulse_width,
rv_sensitivity as sensitivity
FROM program_parameters WHERE event_id = 33636)
UNION
(SELECT
0 as lead_id,
'LV' as lead_type,
'' as lead_serial,
final_amplitude as amplitude,
final_pulse_width as pulse_width.
final_sensitivity as sensitivity
FROM program_parameters WHERE event_id = 33636)
UNION
(SELECT
0 as lead_id,
'ATRIAL' as lead_type,
atrial_amplitude as amplitude,
atrial_pulse_width as pulse_width,
atrial_sensitivity as sensitivity
FROM program_parameters WHERE event_id = 33636)
so that my final data is a three row table with columns.
The only key value I have to get this data is the event_id, and there is only one row per event_id in the table.
Is there a better way to get this data into separate rows other than a UNION operation?
UNIONis the right solution here.This is what you need to use when you want to have separate result sets as one set.