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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

don't know if id's can be duplicated, but if so you may need union all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.