Wondering how to return the 1st row in a MySQL group by vs. the last row. Returning a series of dates, but need the first one displayed.
select * from calendar w
Use the min
function insead of max
to return the first row in a group vs the last row.
select min(date) from calendar ...
If you want the entire row for each group, join the table with itself filtered for the min dates on each group:
select c2.* from
(select eventid, min(dt) dt from calendar
where approved = 'pending' group by eventid) c1
inner join calendar c2 on c1.eventid=c2.eventid and c1.dt=c2.dt
group by eventid;
Demo: http://www.sqlize.com/6lOr55p67c