1

I want to copy data from one table into another table where the columns have different names, and am trying to use the following

SELECT `content` AS `name`, `id` AS `orig_id` 
INTO `songs`
FROM `items` 
WHERE `categories` LIKE "%30%"

It doesn't work. How should I go about achieving this?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
wheresrhys
  • 22,558
  • 19
  • 94
  • 162
  • What does "it doesn't work" mean, exactly? Were there error messages? Was there unexpected output? –  Oct 21 '11 at 18:24

3 Answers3

4

You can specify the columns of the destination table as part of the INSERT syntax as shown below.

INSERT INTO songs
    (name, orig_id)
    SELECT content, id
        FROM items
        WHERE categories LIKE '%30%'
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
0

For SQL :

select 
    name as cus, activator as act 
into dbo.pc1
from dbo.Pc
Taz
  • 3,718
  • 2
  • 37
  • 59
0

SELECT INTO is T-SQL syntax.

For MySQL you'd use:

CREATE TABLE songs 
SELECT 
  content AS name
  , id AS orig_id 
FROM items 
WHERE categories LIKE '%30%'
Johan
  • 74,508
  • 24
  • 191
  • 319