按左外部联接表/关联的列/属性排序

时间:2019-02-23 19:33:32

标签: mysql ruby-on-rails activerecord ruby-on-rails-5 sql-order-by

我想通过created_at的{​​{1}}关联对记录进行排序,并进行以下原始MySQL查询(注意:has_manyarticles_author_associations):

article_associations

上面的查询返回的是SELECT DISTINCT `articles`.* FROM `articles` INNER JOIN `articles_author_associations` ON `articles`.`id` = `articles_author_associations`.`article_id` LEFT OUTER JOIN `article_associations` ON `article_associations`.`article_id` = `articles`.`id` AND `article_associations`.`author_id` = 2 WHERE `articles_author_associations`.`author_id` = 2 ORDER BY `article_associations`.`created_at` DESC LIMIT 100 关联(created_at表)上未按LEFT OUTER JOIN排序的文章。

我的问题:为什么?我在做什么错了?

0 个答案:

没有答案