php - Mysql Select from table where a date is max for each unique location_id AND product -
I have a table - record - which looks like this
id | Place_id | Products | Stock | Date === | =================================== 1 | Bakery 1 | Cake | 21 | 2 2 | Bakery 1 | Bread 23 2 3 | Bakery 2 | Cake | 21 | 2 4 | Bakery 2 | Bread 21 | 2 5 | Bakery 1 | Cake | 21 | 3 6 | Bakery 1 | Bread 23 3 7 | Bakery 2 | Cake | 21 | 3 8 Bakery 2 | Bread 21 | 39 Bakery 1 | Cake | 21 | 4 10. Bakery 1 | Bread 23 4 11 | Bakery 2 | Bread 23 4 For each location and for each product, I want to select the line whose highest date value is what will look like ths
ID | Place_id | Products | Stock | Date === | ============= | ======================================== Bakery 2 | Cake | 21 | 39 Bakery 1 | Cake | 21 | 4 10. Bakery 1 | Bread 23 4 11 | Bakery 2 | Bread 23 4 How do I execute it with a query? I can loop through all the places and all the products and build questions, but its time consuming more memory? Record r1 on "post-text" itemprop = "text"> location code, location, maximum (date), location_id, product from the group recorded by location) and r1.date = r2.date
Comments
Post a Comment