1

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

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

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

为了完整起见,这是表模式:

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以确保它确实包含该列,并且我得到了几行,所有行都包含该列(嗯,INSERTs 工作没有错误)。

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

[解决方案]

出于某种原因,正如@MarinSagovac在他的第二个片段中建议的WHERE那样,将查询替换为内部的条件已修复:INNER JOIN

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子句,但语义应该是一样的,对吧?很明显,该列确实存在,因此错误消息有点误导恕我直言。

4

5 回答 5

2

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

于 2012-10-13T22:11:08.310 回答
1

尝试添加反引号:

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

添加尝试:

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  
INNER JOIN `UserFeedback`.`FeedbackType` = 1  ORDER BY `Appointments`.ID ASC
LIMIT 0, 10
于 2012-10-13T22:14:21.290 回答
0
SELECT SQL_CALC_FOUND_ROWS `Appointments`.ID, UserFeedback.FeedbackType, `UserFeedback.FeedbackSubType 
FROM `UserFeedback'
INNER JOIN `Appointments` ON `Appointments`.ID = `UserFeedback`.Appointments_ID 
INNER JOIN `Reasons` ON `UserFeedback`.FeedbackSubType = `Reasons`.ID  
WHERE UserFeedback.FeedbackType = 1  ORDER BY `Appointments`.ID ASC
LIMIT 0, 10

现在就试试

于 2012-10-13T22:16:02.587 回答
0

使用myisam时的外键?

这可能是问题所在

于 2012-10-17T22:18:47.993 回答
-2

在 WHERE 子句中试试这个:

WHERE UserFeedback.FeedbackType = '1'

删除字段名称中的所有引号(')

于 2012-10-13T22:37:33.920 回答