SQL Query for inserting multi column values in to single column
-
27-09-2019 - |
문제
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
제휴하지 않습니다 StackOverflow