【发布时间】:2015-05-10 23:26:21
【问题描述】:
我有两张表如下:
表 1 (t1)
______________________________________________________________________________________________
RequestId | Raised_By | CommentDate | Comment | AttachmentName | Attachment | AttachmentSize |
----------+-----------+-------------+---------+----------------+------------+----------------+
表 2 (t2)
______________________________________________
RequestId | CommentDate | Comment | Raised_By |
----------+-------------+---------+-----------+
注意:CommentDate 是 timestamp
我想从表t1或t2中选择唯一一条记录,其中RequestId=RequestId和CommentDate是最新的。
我的查询如下:
(SELECT Comment from t1 WHERE RequestId = "."\"".$_POST['RequestId']."\" and Raised_By="."\"".$_POST['Raised_By']."\" and CommentDate="."\"".$_POST['CommentDate']."\")
UNION
(SELECT Comment from t2 WHERE RequestId = "."\"".$_POST['RequestId']."\" and Raised_By="."\"".$_POST['Raised_By']."\" )
ORDER BY CommentDate DESC
LIMIT 1
但我收到一条错误消息,提示 unknown column CommentDate。
【问题讨论】:
-
嗯,所以也许您需要限定列名。你能显示你的桌子的布局信息吗?
-
t1-RequestId, Raised_By,CommentDate,Comment,AttachmentName,Attachment,AttachmentSize t2-RequestId, CommentDate,Comment,RaisedBy
标签: php mysql mysqli mysql-workbench