I have a table that I'm trying to filter data on.
+-------------+-------------+------------+------------+---------------------+
| mod_coli_id | line_number | total_cost | total_sell | modify_date |
+-------------+-------------+------------+------------+---------------------+
| 1403974 | 1 | 544.5000 | 640.5900 | 2016-09-13 13:21:15 |
| 1403976 | 1 | 544.5000 | 640.5900 | 2016-09-13 13:26:54 |
| 1403986 | 1 | 544.5000 | 544.5000 | 2016-09-13 13:35:49 |
| 1405972 | 1 | 544.5000 | 544.5000 | 2016-09-15 10:02:11 |
+-------------+-------------+------------+------------+---------------------+
When I run the following query,
SELECT mod_coli_id,line_number,total_cost,total_sell,max(modify_date) as modify_date
From mod_customer_order_line_item
Where customer_order_id=17761 AND modify_date<='2016-09-14'
The result I get is this.
+-------------+-------------+------------+------------+---------------------+
| mod_coli_id | line_number | total_cost | total_sell | modify_date |
+-------------+-------------+------------+------------+---------------------+
| 1403974 | 1 | 544.5000 | 640.5900 | 2016-09-13 13:35:49 |
+-------------+-------------+------------+------------+---------------------+
Seems like MySQL is returning the first result (mod_coli_id of 1403974) and the max modify_date.
The result that I'm trying to get would be the oldest modify date for each line number (as there could be multiple line_numbers). Eg.
+-------------+-------------+------------+------------+---------------------+
| mod_coli_id | line_number | total_cost | total_sell | modify_date |
+-------------+-------------+------------+------------+---------------------+
| 1403986 | 1 | 544.5000 | 544.5000 | 2016-09-13 13:35:49 |
+-------------+-------------+------------+------------+---------------------+
Any thoughts?
EDIT: Clarified the result I'm looking for.