【发布时间】:2019-11-16 12:18:23
【问题描述】:
我很抱歉,但我无法理解这一点(即使在搜索和尝试了一些东西之后也是如此)。我要做的就是连接两个表,然后在 article_translations 表中的 created_at 上对连接进行降序排序。但是,我需要唯一的条目。
我有两张桌子:
articles
--------
id
user_id
article_translations
--------
id
article_id (brings this table together with the other one)
locale
title
...
created_at
updated_at
执行mysql查询:
SELECT * from articles
JOIN article_translations as t on t.article_id = articles.id
ORDER BY t.created_at desc
我得到了带有相应相关条目的连接表。
articles.id t.article_id created_at
1 1 ''
1 1 ''
2 2 ''
当我尝试不删除重复项时,在这种 id = 1 的文章的情况下,我得到一个严重的错误:
SELECT 列表的表达式 #3 不在 GROUP BY 子句中,并且包含非聚合列“blog.t.id”,它在功能上不依赖于 GROUP BY 子句中的列;这与 sql_mode=only_full_group_by 不兼容
期望的结果是:
articles.id t.article_id created_at
1 1 ''
2 2 ''
任何帮助请...谢谢!
【问题讨论】:
-
继续你向我们展示的样本数据,你想保留两个重复的
created_at值吗? -
换句话说,即使一篇文章可能有多个翻译,您只想要最近的一个?
标签: mysql