MySQL MySQL更新查询中“字段列表”错误中的未知列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1346209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:59:25  来源:igfitidea点击:

Unknown column in 'field list' error on MySQL Update query

mysqlsqlmysql-error-1054

提问by me_here

I keep getting MySQL error #1054, when trying to perform this update query:

尝试执行此更新查询时,我不断收到 MySQL 错误 #1054:

UPDATE MASTER_USER_PROFILE, TRAN_USER_BRANCH
SET MASTER_USER_PROFILE.fellow=`y`
WHERE MASTER_USER_PROFILE.USER_ID = TRAN_USER_BRANCH.USER_ID
AND TRAN_USER_BRANCH.BRANCH_ID = 17

It's probably some syntax error, but I've tried using an inner join instead and other alterations, but I keep getting the same message:

这可能是一些语法错误,但我尝试使用内部联接和其他更改,但我不断收到相同的消息:

Unknown column 'y' in 'field list' 

回答by tuergeist

Try using different quotes for "y" as the identifier quote character is the backtick (“`”). Otherwise MySQL "thinks" that you point to a column named "y".

尝试对“y”使用不同的引号,因为标识符引号字符是反引号(“`”)。否则 MySQL“认为”您指向名为“y”的列。

See also MySQL 5 Documentation

另请参阅MySQL 5 文档

回答by ShoushouLeb

Enclose any string to be passed to the mysql server inside single quotes; e.g.:

将要传递给 mysql 服务器的任何字符串括在单引号内;例如:

$name = "my name"
$query = " INSERT INTO mytable VALUES ( 1 , '$name') "

Note that although the query is enclosed between double quotes, you mustenclose any string in single quotes.

请注意,尽管查询被双引号括起来,但您必须将任何字符串括在单引号中。

回答by ShoushouLeb

You might check your choice of quotes (use double-/ single quotes for values, strings, etc and backticks for column-names).

您可以检查您选择的引号(对值、字符串等使用双引号/单引号,对列名使用反引号)。

Since you only want to update the table master_user_profileI'd recommend a nested query:

由于您只想更新表,master_user_profile我建议使用嵌套查询:

UPDATE
   master_user_profile
SET
   master_user_profile.fellow = 'y'
WHERE
   master_user_profile.user_id IN (
      SELECT tran_user_branch.user_id
      FROM tran_user_branch WHERE tran_user_branch.branch_id = 17);

回答by Aminah Nuraini

In my case, it was caused by an unseen trailing space at the end of the column name. Just check if you really use "y" or "y " instead.

就我而言,它是由列名末尾的一个看不见的尾随空格引起的。只需检查您是否真的使用“y”或“y”。

回答by Masterchief

While working on a .Net app build with EF code first, I got this error message when trying to apply my migration where I had a Sql("UPDATE tableName SET columnName = value");statement.

在首先使用 EF 代码构建 .Net 应用程序时,当我尝试在我有Sql("UPDATE tableName SET columnName = value");语句的地方应用迁移时收到此错误消息。

Turns out I misspelled the columnName.

原来我拼错了 columnName。

回答by Dean Chiu

Just sharing my experience on this. I was having this same issue. The insert or update statement is correct. And I also checked the encoding. The column does exist. Then! I found out that I was referencing the column in my Trigger. You should also check your trigger see if any script is referencing the column you are having the problem with.

只是分享我在这方面的经验。我遇到了同样的问题。插入或更新语句是正确的。我还检查了编码。该列确实存在。然后!我发现我正在引用我的触发器中的列。您还应该检查您的触发器,看看是否有任何脚本引用了您遇到问题的列。

回答by user674669

Just sharing my experience on this. I was having this same issue. My query was like:

只是分享我在这方面的经验。我遇到了同样的问题。我的查询是这样的:

select table1.column2 from table1

However, table1 did not have column2 column.

但是,table1 没有 column2 列。

回答by mannedear

I too got the same error, problem in my case is I included the column name in GROUP BYclause and it caused this error. So removed the column from GROUP BYclause and it worked!!!

我也遇到了同样的错误,我的问题是我在GROUP BY子句中包含了列名,它导致了这个错误。所以从GROUP BY子句中删除了列,它起作用了!!!

回答by Poorna

If it is hibernate and JPA. check your referred table name and columns might be a mismatch

如果是hibernate和JPA。检查您引用的表名和列可能不匹配

回答by Eternal21

I got this error when using GroupBy via LINQ on a MySQL database. The problem was that the anonymous object property that was being used by GroupBy did not match the database column name. Fixed by renaming anonymous property name to match the column name.

在 MySQL 数据库上通过 LINQ 使用 GroupBy 时出现此错误。问题是 GroupBy 使用的匿名对象属性与数据库列名称不匹配。通过重命名匿名属性名称以匹配列名称来修复。

.Select(f => new 
{
   ThisPropertyNameNeedsToMatchYourColumnName = f.SomeName
})
.GroupBy(t => t.ThisPropertyNameNeedsToMatchYourColumnName);