The following query,
select shelf_id, issue_date, current_qty
from Stock
where barcode = '555' and issue_date <= '2018-05-30 14:28:32'
will give the following results,
10  2018-05-25 00:00:00 5
10  2018-05-28 00:00:00 55
5   2018-05-29 00:00:00 100
Adding group by shelf_id will lead to that result,
10  2018-05-25 00:00:00 5
5   2018-05-29 00:00:00 100
The desired result is the following.
10  2018-05-28 00:00:00 55
5   2018-05-29 00:00:00 100
The reasoning behind this, is that for each group I would like to return the row of the group with the latest issue_date.
limit 1 limits the total groups returned to just one,
having issue_date... would be a possible solution but I do not know how to get the closest date to Max(issue_date)
Is it possible at all to accomplish this without using a subquery?
Edit:
The second condition in the where clause issue_date <= '2018-05-30 14:28:32' is a user input issue_date <= ?2 ment to initially filter the table, the query then should group by the results per shelf_if, but return the row with the closest day to the max(issue_date). So I don't see how I could just replace this condition with a subquery. 
 
     
     
    