【发布时间】:2017-10-17 05:45:04
【问题描述】:
我有两张桌子 started_chats 和 chats,我想根据上次发送的聊天订购 started_chats。所以这是我的查询
SELECT started_chats.*
FROM started_chats
WHERE User1='1' OR User2='1'
INNER JOIN chats ON (chats.From_='1' OR chats.To_='1')
AND (chats.To= started_chats.User1 OR
chats.To= started_chats.User2)
ORDER BY chats.Date DESC
所以首先我从started_chats 中选择所有内容,其中 User1 或 User2 等于 1。之后我加入聊天表以选择从 1 发送给其他用户的最后一次聊天(例如,如果 User1 为 1,那么我我正在寻找从 User1 到 User2 的聊天)。但是这个查询给了我以下错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN chats ON (chats.From_='1' OR chats.To_='1') AND (chats.To= started_ch
【问题讨论】: