The initial table is like this:
Fruit | Item_ID | Production_line | Amount_produced | Production_date
---------------------------------------------------------------
Apples | 652 | 1 | 24 | 2016-05-12
Pears | 455 | 4 | 54 | 2016-05-16
Pears | 455 | 2 | 26 | 2016-05-13
Apples | 652 | 6 | 65 | 2016-05-14
Apples | 652 | 3 | 24 | 2016-05-21
Pears | 455 | 7 | 54 | 2016-05-17
Pears | 455 | 5 | 26 | 2016-05-15
Apples | 652 | 8 | 65 | 2016-05-22
What I would like to see as a result is the highest level production line (as they are numbered from 1 up according to the level where they are situated) grouped by Item_ID along with all the other columns:
Fruit | Item_ID | Production_line | Amount_produced | Production_date
---------------------------------------------------------------
Pears | 455 | 7 | 54 | 2016-05-17
Apples | 652 | 8 | 65 | 2016-05-22
When I use SELECT with the MAX(Production_line) along with GROUP BY Item_ID at the end of my query to group the fruit according to the Item_ID, I don't get the correct production date (not sure if it pulls the random one or what) nor the correct amount produced.
I do not have a PRIMARY KEY in this table.
I'm working in phpMyAdmin with MySQL.