我使用3.2.2和MySQL。我有一个方法( has_many :through ActiveRecord::Associations),它生成以下SLQ查询:
SELECT DISTINCT `articles`.*
FROM `articles`
INNER JOIN `articles_comments_associations` `comment_associations_articles`
ON `comment_associations_articles`.`article_id` = `articles`.`id`
INNER JOIN `articles_comments_associations`
ON `articles`.`id` = `articles_comments_associations`.`article_id`
WHERE `articles_comments_associations`.`comment_id` = 223
AND (articles_comments_associations.user_id IN (2))我想了解它是什么意思INNER JOIN 'articles_comments_associations' 'comment_associations_articles' (注意:INNER JOIN有多个数据库表语句),以及由于我没有一个名为comment_associations_articles的数据库表,所以SQL查询是如何工作的。是一个错误(即使它按预期工作)
发布于 2012-06-26 15:03:12
它是一个表别名。也就是说,它将表articles_comments_associations重命名为comment_associations_articles,以便在查询中进一步引用。任何字段或表都可以通过简单地在表/字段引用之后指定另一个名称来别名。
https://stackoverflow.com/questions/11210241
复制相似问题