I think I will have to write some code or a very fancy query to accomplish this, but thought I would ask. We have a log that stores changes to tables. The field_name is the column name, the name_table is the table name, and the name_pk is the primary key. id_row is the value for the primary key and the snapshot is what the value was. I am able to select the snapshot, but within the same query I would like to return what the current value is. Below I attempt using udv's within a sub query, but I don't believe MySQL will support this.
Of course I try to do it without code and without multiple queries first, prospects look dismal. Any suggestions?
SELECT
@field:= field_name, id_row, change_type, @tbl:= name_table, @pk:= name_pk, snapshot,
(SELECT @field FROM @tbl WHERE @pk = log_record_change.id_row) as current_value
FROM
log_record_change
INNER JOIN
log_field_change ON log_field_change.id_record_change = log_record_change.id
INNER JOIN
log_table ON log_table.id = log_record_change.id_table
WHERE
log_record_change.id_change = 36