Pergunta

Eu tenho a tabela "multicol" como abaixo

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

Quero inserir todos os IDs de Rahul na tabela "Singlecol" (mostrado abaixo), que está tendo apenas uma coluna chamada "IDS"

Então, eu quero o resultado como mostrado abaixo

Tabela "Singlecol"

IDS
1002
4521
4854

Qual padrão de consulta será mais eficiente em termos de tempo e espaço?

Foi útil?

Solução

Que tal agora:

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'

Isso deve pegar todos os três id para Rahul e inseri -los SingleCol

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top