Right, I'm trying to do this query on a database. I've got two tables, parent and child. Each parent row has an id, a datestamp, and a few other things on it. Each child entry also has an id, a datestamp, other stuff and the id of the parent it's tied to. So there can be many children tied to a parent.
What I need to do, is to select every parent sorted by the datestamp desc of the most recent comment tied to that parent. If there is no comment, it should use the datestamp of the parent.
I've been playing around with max(datestamp) and left joins, but can't for the life of me get this to work. I'm using MSSQL, so the limit command goes right out the window.
Any ideas?
What I need to do, is to select every parent sorted by the datestamp desc of the most recent comment tied to that parent. If there is no comment, it should use the datestamp of the parent.
I've been playing around with max(datestamp) and left joins, but can't for the life of me get this to work. I'm using MSSQL, so the limit command goes right out the window.
Any ideas?