我知道這個問題已經被問過了幾千次,我嘗試了千次提示,但仍然沒有成功。我應用了DISTINCT,group by等等,現在我需要你的幫助。 只從表中獲取重複記錄一次?
我需要做的。如果表中的字段to
或from
等於SESSION_ID然後檢索表中的記錄,我要檢索的記錄只有一次,如果有from
它的值是6,然後檢索和不檢索另一個form
或to
列其ID值6
select table.id, table.from, table.to, table.message, table.sent, table.read, table.direction from table where ((table.to ='82') or (table.from = '"82')) order by table.id DESC
我嘗試了DISTINCT和GROUP BY,但沒有成功。
SELECT DISTINCT table.id, table.from, table.to, table.message, table.sent, table.read, table.direction FROM table WHERE ((table.to = '82') OR (table.from = '82')) GROUP BY table.from, table.to ORDER BY table.id DESC LIMIT 0 , 30
在此先感謝。
可以粘貼與組查詢由你試過嗎? –
我不明白。對於我列出的示例數據沒有重複,每個ID都是不同的,每個消息都有不同的內容。那麼你期待的結果是什麼? – xQbert
@Niranjan SELECT DISTINCT table.id,table.from,table.to,table.message,table.sent,table.read,table.direction FROM表 WHERE( ( table.to = '82' ) OR( table.from = '82' ) ) GROUP BY table.from,table.to ORDER BY table.id DESC LIMIT 0,30 –