簡體   English   中英

MySQL訂單基於其他表的值

[英]MySql order based on the value from other table

我有兩個表started_chatschats ,我想訂購started_chats基於上次聊天sent.So這里是我的查詢

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的所有內容。之后,我加入chats表以選擇從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

加入后發件人

SELECT started_chats.* 
FROM started_chats 
INNER JOIN chats ON (chats.From_='1' OR chats.To_='1')
WHERE User1='1' OR User2='1' 
AND (chats.To= started_chats.User1 OR chats.To= started_chats.User2)
ORDER BY chats.Date DESC

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM