我在 MariaDB 中有两个表,我需要在左表中显示它们的当前分数与历史表中的最新分数不同的表。
例如:
users
id name current_score
1 Bob 4
2 Tom 5
3 Fred 3
4 Tim 3
5 Ian 4
histories
id user_id score date
1 1 3 2018-11-13
2 1 4 2018-11-12
3 1 2 2018-11-11
4 2 5 2018-11-12
在上面我想显示鲍勃,因为他的最新历史与他目前的得分不同,但不显示汤姆,因为他是一场比赛
我尝试使用类似的东西:
SELECT u.id, u.name, u.current_score
FROM users u
where u.current_score not in
(select h.score from histories h where
h.user_id=u.id order by h.date desc limit 1)
这引发了一个错误:
#1235 - This version of MariaDB doesn't yet support
'LIMIT & IN/ALL/ANY/SOME subquery'
如果我删除限制 1,那么它会返回用户中的几乎所有行 - 每个表中有几千行,但我认为它应该返回 50 左右,但它在 4,285 个可能的行中返回超过 4,100 行