0

この要件があり、MySQl データベースを使用しています

コメント表

id  user id  ariticle_id     comment        comment date
========================================================
 1     45        2           comment1          02/03/12
 2     45        2           comment2          03/03/12
 3     45        2           comment3          04/03/12 
 4     45        2           comment4          05/03/12
 5     45        2           comment5          06/03/12
 6     45        5           comment7          04/03/12
 7     45        5           comment8          05/03/12
 8     45        5           comment9          06/03/12

記事表

id   article_text               article_date
============================================
2    Some text                  01/03/12
2    updated text               04/03/12
5    another text               03/03/12
5    another updated text       04/03/12

コメントテーブルと記事テーブルからすべての詳細 userid、article_id、article_text、comment、comment_date を取得したい

特定の記事 id =2 ユーザー id =45 の詳細は、記事の更新後に作成されます。

予想される出力は次のようになります

 user_id   article_id   comment           commentdate
     45        2           comment3          04/03/12
     45        2           comment4          05/03/12
     45        2           comment5          06/03/12

道に迷っています助けてください、MYSQL でクエリを実行しようとしています

4

3 に答える 3

2

使用しているIDを具体的に指定する必要があります。これを試して、

Select * from comment_table
join article_table on article_table.id = comment_table.id
于 2012-05-07T06:23:07.687 に答える
1

今、私はあなたの要求をキャッチしたと思います

しかし、記事テーブルに重複したIDがあります

これを修正した後、このSQLで試すことができます

SELECT  c.userid,
        c.article_id,
        c.comment,
        c.commentDate
FROM   comment_table c 
INNER JOIN article_Table a
ON     a.id = c.ariticle_id
AND    c.article_id = 2 
AND    c.userid = 45 

WHERE   c.commentDate >= (SELECT article_date
                          FROM article_date
                          WHERE id = c.ariticle_id )
于 2012-05-07T08:03:39.537 に答える
0

お役に立てれば:

SELECT  a.userid,
        a.article_id,
        b.article_text,
        a.comment,
        a.commentDate
FROM    comment_table a INNER JOIN article_Table b
           ON a.article_ID = b.article_ID
WHERE   a.article_id = 2 AND a.userid = 45 AND
            b.commentdate > date('2012/04/03')
于 2012-05-07T06:22:01.343 に答える