选择最后3个不同的行mysql

时间:2014-10-01 13:27:39

标签: mysql select

如何选择最后不同的行?

视频 - table1

idvideo name                       
1684    Uno spettacolo da rimanerci
1301    Ciao
1684    Ciamooooo
1823    Prova
1333    Prova2

VIDEOS_VIEWS - table2

idvideo dateview
1684    09-01-2014 11.30
1684    09-01-2014 11.31
1823    09-01-2014 11.31
1684    09-01-2014 11.32
1333    09-01-2014 11.33
1684    09-01-2014 11.34
1333    09-01-2014 11.35

我想要这个结果:

idvideo dateview          name
1333    09-01-2014 11.35  Prova2
1684    09-01-2014 11.34  Ciamooooo
1823    09-01-2014 11.31  Prova

这是当前查询,但太低了。

SELECT * 
FROM videos_views  
INNER JOIN videos  
    ON videos_views.idvideo = videos.idvideo 
GROUP BY videos_views.idvideo
ORDER BY MAX(videos_views.dateview)
DESC LIMIT 3

0 个答案:

没有答案