wannabeprogrammer wannabeprogrammer - 10 days ago 5
MySQL Question

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

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

You simply have to do:

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