查询没有任何问题,除了您使用单引号:
INSERT INTO topics (personID)
SELECT personID FROM persons where personID = 1
如果您在 MySQL 中使用保留字,则应使用反引号 `(通常在键盘上的 1 旁边)包含名称。
请参见以下示例:
mysql> select * from test1;
+------+-------+
| id | varry |
+------+-------+
| 1 | aaa |
+------+-------+
1 row in set (0.07 sec)
mysql> select * from test2;
+------+-------+-------+
| id | barry | third |
+------+-------+-------+
| 1 | ccc | NULL |
| NULL | d | 1 |
| NULL | d | 2 |
| NULL | d | 3 |
+------+-------+-------+
4 rows in set (0.00 sec)
mysql> insert into test1 (id) select id from test2 where barry='ccc';
Query OK, 1 row affected (0.04 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> insert into test1 ('id') select 'id' from test2 where barry='ccc';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ''id')
select 'id' from test2 where barry='ccc'' at line 1
mysql>