Constant value in insert select

INSERT INTO linking_book_category (book_id, category_id)
SELECT book.id, 1 FROM books AS book;

More advance usage involving substring, trimming leading zeros as I try to migrate college’s intake from migration table.

INSERT INTO intakes (no,month,year,active,`status`,createdby,datecreated)
SELECT DISTINCT academicperiod, TRIM(LEADING '0' FROM SUBSTR(academicperiod,6,2)), SUBSTR(academicperiod,1,4), 1, 1, 1, NOW()
FROM _prestige_intake
WHERE academicperiod IN ('2006/01','2006/07','2007/01','2007/07','2008/01','2008/07','2009/01','2009/07','2010/01','2010/07')
ORDER BY academicperiod ASC
Facebook Twitter Email

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>