简体   繁体   中英

ambiguous error in mysql recordset in Dreamweaver

The following recordset in Dreamweaver throws a 1052 ambiguous error every time I attempt to test it. I know it has something to do with the dateADDED, but don't know how to fix it.

    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 :

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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