atulquest93 atulquest93 - 24 days ago 9
SQL Question

How to select top 3 dates SQL

I have the following table structure..

id title Date
1 Abc 14 Nov 2016
2 Abc 14 Nov 2016
3 Abc 13 Nov 2016
4 Abc 13 Nov 2016
5 Abc 13 Nov 2016
6 Abc 12 Nov 2016
7 Abc 12 Nov 2016
8 Abc 11 Nov 2016
9 Abc 11 Nov 2016


How to select data of top 3 dates only.. .
means data of columns have date as
14,13, 12.


or may be next 3 dates.. like only data of
13,12,11
or only
12,11


NOt getting any idea how to make it.. using
MYSQL

Answer

Join with a subquery that gets the top 3 dates.

SELECT a.*
FROM YourTable AS a
JOIN (SELECT DISTINCT Date
      FROM YourTable
      ORDER BY Date DESC
      LIMIT 3) AS b
ON a.Date = b.Date