I have two tables in MariaDB where I need to show those in the left table where their current score is not the same as the most recent score in the history table.
For example:
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
In the above I would want to show Bob as his latest history is not the same as his current score but not show Tom as his is a match
I tried using something like:
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)
This threw an error:
#1235 - This version of MariaDB doesn't yet support
'LIMIT & IN/ALL/ANY/SOME subquery'
If I remove the limit 1 then it returns almost all the rows in users - there are a few thousands rows in each tables but I think it should return around 50 but it is returning over 4,100 rows out of 4,285 possible rows