简体   繁体   English

在Dreamweaver中的MySQL记录集中存在歧义错误

[英]ambiguous error in mysql recordset in Dreamweaver

The following recordset in Dreamweaver throws a 1052 ambiguous error every time I attempt to test it. 每当我尝试对其进行测试时,Dreamweaver中的以下记录集都会引发1052模糊错误。 I know it has something to do with the dateADDED, but don't know how to fix it. 我知道它与dateADDED有关,但不知道如何解决。

    SELECT commentID, commentTitle, commentContent, topicTable.topicTitle,  DAYNAME(dateADDED) as day, MONTHNAME(dateADDED) as month, 
DAY(dateADDED) as date, YEAR(dateADDED) as year
FROM commentTable, topicTable
WHERE commentID = colname AND topicTable.topidID = commentTable.topicID

Here is the layout of the tables, 这是表格的布局,

CREATE TABLE userTable
(
userID VARCHAR(15) NOT NULL,
screenName VARCHAR(15) NOT NULL UNIQUE,
userPasswd CHAR(40) NOT NULL,
firstName VARCHAR(15) NOT NULL,
lastName VARCHAR(25) NOT NULL,
dateJoined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
lastlogin DATETIME,
PRIMARY KEY(userID)
)
;

CREATE TABLE categoryTable                                          
(
categoryID MEDIUMINT AUTO_INCREMENT NOT NULL,                       
categoryName VARCHAR(30) NOT NULL,                                  
categoryDescription VARCHAR(200) NOT NULL,                          
PRIMARY KEY (categoryID)
)
;

CREATE TABLE topicTable                                             
(
topicID MEDIUMINT AUTO_INCREMENT NOT NULL,                          
topicTitle VARCHAR(30) NOT NULL,                                    
userID VARCHAR(15) NOT NULL,                                        
dateAdded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,             
categoryID MEDIUMINT NOT NULL,                                      
PRIMARY KEY (topicID)
)
;

CREATE TABLE commentTable                                           
(
commentID MEDIUMINT AUTO_INCREMENT NOT NULL,                        
commentTitle VARCHAR(30) NOT NULL,                                  
commentContent TEXT NOT NULL,                                       
userID VARCHAR(15) NOT NULL,                                        
dateAdded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,             
topicID INT NOT NULL,                                               
PRIMARY KEY (commentID)
)
;

dateADDED is represented in both tables, so you should choose from which one you want it to be in the result set : dateADDED在两个表中都有表示,因此您应该从结果表中选择一个:

SELECT ct.commentID
     , ct.commentTitle
     , ct.commentContent
     , tt.topicTitle
     , DAYNAME(ct.dateADDED) as `day`
     , MONTHNAME(ct.dateADDED) as `month`
     , DAY(ct.dateADDED) as `date`
     , YEAR(ct.dateADDED) as `year`
FROM commentTable ct
JOIN topicTable tt ON ct.commentID = tt.colname  AND tt.topidID = ct.topicID

By the way, still wonder, what colname stands for, maybe it should be ct.userID = tt.userID instead? 顺便说一句,仍然不知道,什么colname代表,也许应该是ct.userID = tt.userID呢?

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

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