문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top