我让这个 SQL 查询工作得很好。我对数据库做了一些小改动,然后重新运行它,它就停止了工作。
master_followups
我的目标是加入followups_fb_messages.message_text
但只为每个 UID 返回一行,master_followups
其中最近followups_fb_messages.message_text
加入了它。
SELECT master_followups.*,
followups_fb_messages.message_text,
followups_fb_messages.message_time
FROM
master_followups
LEFT JOIN followups_fb_messages
ON master_followups.UID = followups_fb_messages.FID
AND followups_fb_messages.message_time =
(SELECT
MAX(followups_fb_messages.message_time)
FROM followups_fb_messages
WHERE followups_fb_messages.FID = master_followups.UID
)
我一直试图弄清楚过去一个小时发生了什么。
这不是按预期返回 100 个结果,而是返回 340。我检查了数据库,它显示 100 行 inmaster_followups
和 340 行 in followups_fb_messages
。
大约一个小时前,我有这个确切的查询工作正常,然后它停止了。也许我改变了一些东西,但我看不到它。