I have the following table, table name source_data
column1 values table col group_flag index
-- -- -- -- -- --
id 1 users oid 1 1
fName dan users firstName 0 1
lName opera users lastName 0 1
oid 2 users oid 1 2
fName fan users firstName 0 2
lName popa users lastName 0 2
id 3 users oid 1 3
fName oana users firstName 0 3
lName jon users lastName 0 3
That data represent the mapping of data to be inserted in table mentioned in column "table". The "group_flag" represent by which column data should be grouped.
So according to these data I need have in "users" table 3 records, like
insert into users (oid,firstName,lastName) values (1,'dan','opera');
insert into users (oid,firstName,lastName) values (2,'fan','popa');
insert into users (oid,firstName,lastName) values (3,'oana','jon');
How to write the query from "source_data" table to generate such insert statements ?