我已經得到了表INSERT INTO與SELECT和一些默認值
person
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | NO | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
和
chatroom
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| col1 | int(11) | YES | | NULL | |
| col2 | int(11) | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
,我想執行以下語句(每個person
在chatroom
添加一行id
和col2
列的相應person.id
和DEFAULT
和NULL
值)
INSERT INTO chatroom (DEFAULT, col1, NULL) SELECT DEFAULT, id AS col1, NULL FROM person;
但它不起作用。 有人可以糾正查詢嗎?