简体   繁体   English

表中的 SQLite 列与表同名

[英]SQLite column in table has same name as table

Hi there I have a database movies that contains a table country, with a column also called country.嗨,我有一个数据库电影,其中包含一个国家/地区表,其中有一列也称为国家/地区。 when attempting to use this column I have tried尝试使用此列时,我尝试过

country."country"
country.country
country FROM country

screenshot of my screen showing that there is a table named country and a column also called country, with the error in the right hand sidebar:我的屏幕截图显示有一个名为 country 的表和一个也称为 country 的列,右侧边栏中出现错误:

我的屏幕截图显示有一个名为 country 的表和一个也称为 country 的列,右侧边栏中有错误

but the fact that they are the same name just keeps throwing an error.但是它们同名的事实只会不断抛出错误。 I am about to put my head through a wall I'm getting so frustrated.我正要穿过一堵墙,我感到非常沮丧。 I have combed google and stack, but they just require that the table not have the same name as the database.我梳理了谷歌和堆栈,但他们只要求表与数据库的名称不同。 I cannot seem to find a fix for this, any help is appreciated, and I am sorry if this has indeed been posted and answered elsewhere and I somehow missed it.我似乎无法解决这个问题,任何帮助表示赞赏,如果这确实已在其他地方发布并回答,我很抱歉,我不知何故错过了它。

This is not about the table/column name: having a table column with the same name as the table it belongs to is unambiguous in SQL, since the syntax is clear enough about where a column name or a table name is expected.这与表/列名无关:在 SQL 中具有与其所属表同名的表列是明确的,因为语法对于列名或表名的预期位置已经足够清楚。

Table country is not part of the from clause of your query, hence it is not available in the select clause.country不是查询的from子句的一部分,因此它在select子句中不可用。

You need to join that table, presumably with the incountry table:您需要join该表,大概是与incountry表:

inner join country on country.cid = incountry.cid

Then you can add country.country to the select clause.然后您可以将country.country添加到select子句中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM