I have the following table
id | item_id | start_date | end_date | disc_percent
1 | 1 | 2016-12-27 | 2016-12-31 | 50
2 | 2 | 2016-12-27 | 2016-12-31 | 50
3 | 3 | 2016-12-27 | 2016-12-31 | 50
4 | 137 | 2016-12-27 | 2016-12-31 | 50
5 | 1 | 2016-12-28 | 2016-12-29 | 10
and I am running this query:
SELECT *
from onsale
WHERE (CURDATE() BETWEEN onsale.start_date
AND onsale.end_date)
order by onsale.start_date DESC,
onsale.end_date ASC
I want to get only the first record of each item_id like this:
id | item_id | start_date | end_date | disc_percent
5 | 1 | 2016-12-28 | 2016-12-29 | 10
2 | 2 | 2016-12-27 | 2016-12-31 | 50
3 | 3 | 2016-12-27 | 2016-12-31 | 50
4 | 137 | 2016-12-27 | 2016-12-31 | 50
how can I get this result? Thanks for the help