当使用带有多个数据库表语句的INNER JOIN时,什么意思/发生? [英] What means / happens when using the `INNER JOIN` with multiple database table statements?
问题描述
我使用Ruby on Rails 3.2.2和MySQL。我有一个方法( has_many:通过
ActiveRecord :: Associations
)生成以下SLQ查询:
I am using Ruby on Rails 3.2.2 and MySQL. I have a method (an has_many :through
ActiveRecord::Associations
) that generates the following SLQ query:
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))
$ b b
我想理解它的含义 INNER JOIN'articles_comments_associations''comment_associations_articles'
(注意:有多个数据库表语句 INNER JOIN
)以及SQL查询的工作原理,因为我没有名为的数据库表 $ c>
。 是错误(即使它按预期工作)?
I would like to understand what it means INNER JOIN 'articles_comments_associations' 'comment_associations_articles'
(note: there are multiple database table statements for the INNER JOIN
) and how it is possible that the SQL query works since I do not have a database table named comment_associations_articles
. Is it an error (even if it works as expected)?
推荐答案
p>它是一个表别名。意思是,为了在查询中进一步引用,将表 articles_comments_associations
重命名为 comment_associations_articles
。任何字段或表都可以通过简单地在表/字段引用之后提供另一个名称来进行别名。
It is a table alias. Meaning, it is renaming the table articles_comments_associations
to comment_associations_articles
for the purpose of further references in the query. Any field or table can be aliased by simply giving another name following the table/field reference.
这篇关于当使用带有多个数据库表语句的INNER JOIN时,什么意思/发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!