php - `where` 子句中的未知列

标签 php mysql

我收到标题中描述的错误:

Unknown column 'FeedbackType' in 'where clause'

但是我不明白为什么。这是我的查询:

SELECT SQL_CALC_FOUND_ROWS `Appointments`.ID, FeedbackType, FeedbackSubType 
FROM `UserFeedback`
INNER JOIN `Appointments` ON `Appointments`.ID = `UserFeedback`.Appointments_ID 
INNER JOIN `Reasons` ON `UserFeedback`.FeedbackSubType = `Reasons`.ID  
WHERE `FeedbackType` = 1  ORDER BY `Appointments`.ID ASC
LIMIT 0, 10

FeedbackTypeUserFeedback 表中的一列,大小写正确,已经检查了几次。

为了完整起见,这是表架构:

CREATE TABLE IF NOT EXISTS `UserFeedback` 
(
   ID bigint(20) NOT NULL AUTO_INCREMENT,
   FeedbackType int(4) NOT NULL,
   FeedbackSubType int(4) NOT NULL,
   Notes varchar(170) NULL,
   Appointments_ID bigint(20) NOT NULL,
   IpTracking_ID bigint(20) NOT NULL,
   PRIMARY KEY (ID),
   FOREIGN KEY (Appointments_ID) REFERENCES Appointments(Id), 
   FOREIGN KEY (IpTracking_ID) REFERENCES IpTracking(Id)    
)
ENGINE=MyISAM DEFAULT CHARSET=utf8;

可能是什么问题?

[编辑]

这些变体也不起作用(因为 FeedbackType 不包含保留字/字符,只属于 UserFeedback 表):

... WHERE UserFeedback.FeedbackType = 1
... WHERE `UserFeedback`.`FeedbackType` = 1
... WHERE FeedbackType = '1'
etc.

(实际上我看不出他们应该这么做的理由)

[编辑 2]

我运行 SELECT * FROM UserFeedback 以确保它确实包含该列,并且我得到了几行,所有行都包含该列(嗯,INSERT 没有错误).

对于提到的每个变体,我总是得到相同的错误,总是在 WHERE 子句中。如果我省略 WHERE 子句,我会得到未经过滤的结果(包括这些结果中的 FeedbackType 列),所以这真的很困惑。

[解决方案]

出于某种原因,用 INNER JOIN 中的条件替换 WHERE 查询修复了它,如@MarinSagovac suggested in his second snippet :

SELECT SQL_CALC_FOUND_ROWS `Appointments`.ID, FeedbackType, FeedbackSubType 
FROM `Appointments`
INNER JOIN `UserFeedback` ON `Appointments`.ID = `UserFeedback`.Appointments_ID 
   AND `UserFeedback`.FeedbackType = 1
INNER JOIN `Reasons` ON `UserFeedback`.FeedbackSubType = `Reasons`.ID  
ORDER BY `Appointments`.ID ASC
LIMIT 0, 10

请注意,现在没有 WHERE 子句,但语义应该相同,对吧?很明显该列确实存在,因此错误消息有点误导恕我直言。

最佳答案

您是否尝试过在 where 子句中使用 UserFeedback.FeedbackType?

关于php - `where` 子句中的未知列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12877465/

相关文章:

php - 通过 PHP 脚本中运行的操作将大型变量存储在 HTML5 持久存储中

javascript - ckeditor 将 html 内容显示为纯文本

php - react loop->addPeriodicTimer 的最大间隔为 2147 秒

php - mysql 和 php : Data extraction

Mysql 查询根据子字符串 left() 和列 max() 值查找行

mysql - MySQL中多列索引的字段顺序是否重要

php - 递归获取数组的键并创建下划线分隔的字符串

php - 如何在 Windows Azure 上部署现有的 WordPress 项目

php - 在 PHP 中扩展 mysql JOIN 查询

mysql - SQL - 1388 字符 SQL 查询。 (必须是更简单的解决方案吗?)