MySQL多个SELECT问题

时间:2010-10-12 00:59:37

标签: mysql

如何在不弄乱查询的情况下将以下代码示例1添加到示例2中。

示例1

SELECT *
FROM users 
INNER JOIN users_articles ON users.user_id = users_articles.user_id
WHERE users.active IS NULL
AND users.deletion = 0

示例2

SELECT users.user_id, users_articles.user_id, users_articles.title, articles_comments.article_id, articles_comments.comment, articles_comments.comment_id
FROM users_articles
INNER JOIN articles_comments ON users_articles.id = articles_comments.article_id
INNER JOIN users ON articles_comments.user_id = users.user_id
WHERE users.active IS NULL
AND users.deletion = 0
ORDER BY articles_comments.date_created DESC
LIMIT 50

1 个答案:

答案 0 :(得分:0)

我不确定你在问什么,但这有帮助吗?

SELECT users.user_id, users_articles.user_id, users_articles.title, articles_comments.article_id, articles_comments.comment, articles_comments.comment_id
FROM users_articles
  INNER JOIN articles_comments ON users_articles.id = articles_comments.article_id
  INNER JOIN users ON articles_comments.user_id = users.user_id
WHERE users.active IS NULL
  AND users.deletion = 0
ORDER BY articles_comments.date_created DESC
LIMIT 50

<强>更新

这是你想要的吗?

SELECT users.user_id, users_articles.user_id, users_articles.title, articles_comments.article_id, articles_comments.comment, articles_comments.comment_id
FROM users_articles
  INNER JOIN articles_comments ON users_articles.id = articles_comments.article_id
  INNER JOIN users ON articles_comments.user_id = users.user_id
    AND users.active IS NULL
    AND users.deletion = 0
ORDER BY articles_comments.date_created DESC
LIMIT 50;
SELECT *
FROM users 
  INNER JOIN users_articles ON users.user_id = users_articles.user_id
WHERE users.active IS NULL
  AND users.deletion = 0