我正在使用MySQL。抓取最近觀看的視頻?
我有以下表結構:表名:影片
videoId title description
1 Video title 1 Some description text1
2 Video title 2 Some description text2
3 Video title 3 Some description text3
4 Video title 4 Some description text4
5 Video title 5 Some description text5
然後,我有一個表:WatchedVideos
id videoId Userid date
1 2 234 2009-11-12 04:46:44
2 2 212 2009-11-13 04:46:44
3 3 234 2009-11-13 05:46:44
4 4 235 2009-11-13 06:46:44
5 4 235 2009-11-13 07:46:44
6 1 234 2009-11-13 08:46:44
7 1 234 2009-11-13 09:46:44
現在我想取「影片現在正在觀看」是指列表最新的2個(我會根據自己的情況修改)最近由不同用戶觀看的視頻,但是當我在上述兩個表格之間應用聯合時,它會給出我不想要的重複遊戲,如果一個用戶觀看了相同的視頻兩次然後它給視頻tw o時間,我想單獨列出的視頻的詳細信息如下:
videoId title description
1 Video title 1 Some description text1
4 Video title 4 Some description text4
請告訴我應該提取什麼類型的查詢來獲取這些數據?
THANKS
小姐「由不同的用戶注視」約束 – jitter 2009-11-20 18:12:50
關鍵是要在你希望是唯一的野外使用GROUP BY。也許可以使用 – 2009-11-20 18:16:51
,但是你可以使用「group by v.videoID,w.userID」來解決這個問題^^ – codymanix 2009-11-20 18:17:12