views:

41

answers:

1

I have Table "MultiCol" as below

Name LibraryID RegisterID EngineerID
Rahul 1002      4521       4854
Ajay  5072      3151       4833
Vimal 4532      4531       4354

I want to insert the Rahul's all IDs in the "SingleCol" table(shown below) which is having only one Column named "IDS"

So I want the Result as shown below

Table "SingleCol"

IDS
1002
4521
4854

Which query pattern will be most efficient in terms of time and space?

+2  A: 

How about this:

INSERT INTO SingleCol(IDS)
   SELECT LibraryID FROM MultiCol WHERE Name = 'Rahul'
   UNION
   SELECT RegisterID FROM MultiCol WHERE Name = 'Rahul'
   UNION
   SELECT EngineerID FROM MultiCol WHERE Name = 'Rahul'

That should grab all three ID's for Rahul and insert them into SingleCol

marc_s
@marc_s Thanks!! Appreciate it
SARAVAN
don't know if id's can be duplicated, but if so you may need union all
Paul Creasey
@marc_s Yes got it
SARAVAN