Suppose the two tables "Items" and "ItemModifications":
Items
[blue]id[/blue] (int) PK
[blue]name[/blue] (who cares)
ItemModifications
[blue]item_id[/blue] (int) FK on Items.id
[blue]modification[/blue] (who cares)
[blue]when_modified[/blue] (datetime or timestamp)
In the "ItemModifications" table, I can have multiple modifications (entries in this table) on one item. What I want to do is select the latest entry for each item, as illustraed below:
I want the rows in [red]red[/red] as they are the latest.
Items
[blue]id[/blue] (int) PK
[blue]name[/blue] (who cares)
ItemModifications
[blue]item_id[/blue] (int) FK on Items.id
[blue]modification[/blue] (who cares)
[blue]when_modified[/blue] (datetime or timestamp)
In the "ItemModifications" table, I can have multiple modifications (entries in this table) on one item. What I want to do is select the latest entry for each item, as illustraed below:
Code:
[green][b][Items][/b][/green] table
[b]id[/b] [b]name[/b]
1 pen
2 rock
3 rubber band
[green][b][ItemModifications][/b][/green] table
[b]item_id[/b] [b]modification[/b] [b]when_modified[/b]
1 broken 1:00 PM
1 fixed 3:00 PM
[red]1 melted 3:30 PM[/red]
2 thrown 1:00 PM
[red]2 thrown 1:15 PM[/red]
3 cut 10:00 AM
3 eaten 5:00 PM
[red]3 puked 8:00 PM[/red]