gpt4 book ai didi

mysql - 从另一个 SELECT 向表中插入行 - MySQL

转载 作者:行者123 更新时间:2023-12-01 00:31:37 25 4
gpt4 key购买 nike

我有一个名为 CountriesList 的表,其中包含 IDCountry 列。
我有另一个名为 Entries 的表,其中有一列名为 Country

我想将 Entries 中的所有国家INSERT 到 CountriesList...我使用以下语法:

INSERT INTO CountriesList ('Country') 
SELECT DISTINCT ('Country')
FROM `Entries`

但是,我明白了

1064 - You have an error in your SQL syntax

语法有什么问题?

最佳答案

不要混淆单引号 (') 和反引号 (`)。

反引号用于数据库和列名。

单引号用于字符串。

INSERT INTO `CountriesList`
(`Country`)
SELECT DISTINCT `Country` FROM `Entries`

关于mysql - 从另一个 SELECT 向表中插入行 - MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5152731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com