In MySQL, I have two tables with a 1:n relationship.
Table items has products, whose state is kept in another table, like so :
items:
id |ref_num|name |...
1 |0001 |product1|...
2 |0002 |product2|...
items_states :
id|product_id|state_id|date
1 |1 |5 |2010-05-05 10:25:20
2 |1 |9 |2010-05-08 12:38:00
3 |1 |6 |2010-05-10 20:45:12
...
The states table is not relevant and only relates the state_id to the state name and so on.
How can I get products where the latest state is the one I specify, one item per row?
Thank you