[英]Inserting rows to a table from another SELECT - MySQL
我有一个名为表CountriesList
与ID
和Country
列。
我还有另一个名为Entries
表,该表具有一个名为Country
的列。
我想INSERT
所有国家Entries
进入CountriesList ...我使用的语法如下:
INSERT INTO CountriesList ('Country')
SELECT DISTINCT ('Country')
FROM `Entries`
但是,我得到
1064-您的SQL语法有错误
语法有什么问题?
不要混淆单引号( '
)和反引号( `
)。
反引号用于数据库和列名。
单引号用于字符串。
INSERT INTO `CountriesList`
(`Country`)
SELECT DISTINCT `Country` FROM `Entries`
Insert into entries(country)
select distinct(country) from
countrylist where country not in
(select country from entries)
它应该是 -
INSERT INTO CountriesList
(Country)
SELECT DISTINCT Country FROM Entries
尝试将此插入项(国家/地区)中,从CountrysList选择国家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.