我的硬件中存在以下问题。
列出评论用户的用户ID,用户名和上次登录日期 由给定用户评论的所有文章。 (给定用户ID)
这是我的表格格式:
user(userID:char(10), username:char(30), registrationDate:date,lastLoginDate:date),
article(articleID:char(10), userID:char(10), name:char(80), description:char(130), date:date, rating:int),
comment(commentID:char(10), articleID:char(10), userID:char(10), message:char(130), date:date, rating:int),
我尝试了以下查询来查找评论给定用户评论的所有文章的人。例如,给定的用户ID是U102;
select C.articleID,U.userID, U.username, U.LastLoginDate from user U, comment C where U.userID = C.userID AND C.articleID IN (select articleID from comment where userID= 'U102');
接下来是我的输出:
+-----------+--------+----------------+---------------+
| articleID | userID | username | LastLoginDate |
+-----------+--------+----------------+---------------+
| A105 | U101 | Jon Skeet | 2016-11-29 |
| A105 | U102 | Darin Dimitrov | 2016-11-28 |
| A104 | U105 | VonC | 2016-11-25 |
| A104 | U101 | Jon Skeet | 2016-11-29 |
| A104 | U102 | Darin Dimitrov | 2016-11-28 |
+-----------+--------+----------------+---------------+
但是,这不是我想要的。我的期望是:
+-----------+--------+----------------+---------------+
| articleID | userID | username | LastLoginDate |
+-----------+--------+----------------+---------------+
| A105 | U101 | Jon Skeet | 2016-11-29 |
| A105 | U102 | Darin Dimitrov | 2016-11-28 |
| A104 | U101 | Jon Skeet | 2016-11-29 |
| A104 | U102 | Darin Dimitrov | 2016-11-28 |
+-----------+--------+----------------+---------------+