mysql -> insert into tbl (select from another table) and some default values

wannabeprogrammer picture wannabeprogrammer · May 6, 2011 · Viewed 195.3k times · Source

As the title says, I am trying to insert into one table selecting values from another table and some default values.

INSERT INTO def (catid, title, page, publish) 
(SELECT catid, title from abc),'page','yes')


INSERT INTO def (catid, title, page, publish) 
VALUES
((SELECT catid, title from abc),'page','yes'))

The first query gives a mysql error and the second one gives column count does not match.

What do I need to do?

Answer

Nican picture Nican · May 6, 2011

You simply have to do:

INSERT INTO def (catid, title, page, publish) 
SELECT catid, title, 'page','yes' from `abc`