MySQL – INSERT SELECT – Setting Constant Value
I had a situation arise where I needed to insert data into a linking table where one column was made up of ids from one table, but the other column was set to a default value (1). Never did this type of query before so had a bit of a struggle with it, but finally figured it out.
INSERT INTO linking_book_category (book_id, category_id) SELECT book.id, 1 FROM books AS book;
Notice the 1 after SELECT book.id.

Excellent. I was finding this solution from long time. I am also trying something like, when the query is executed it should pick up existing category id and concatenate ’1′ along with it, instead of simply having value ’1′. Any comments?