I've got a table of users (1,000s) and a table of user messages (100,000s). I want a fast way of getting all users and their most recent message.
What I'm currently using is something like...
SELECT
u.id, u.name,
(
SELECT note FROM msgs
WHERE msgs.uID=u.id
ORDER BY created_date DESC
LIMIT 1
) as note
FROM users u
Right now if I limit that to 20 users, it takes 2.5s ... 200 users takes 45s.
(I already have an INDEX on msgs.uID and msgs.created_date.)
What am I doing wrong? I need a much faster query.