I have 2 tables, a \"document\" table and a \"content\" table. They look like this (simplified):
document table:
docID
docTitle
content table:
contentID
doc
try this:
select d.id, d.docTitle, MAX(c.dateAdd)
from document_table d
left join content_table c
on d.id = c.docId
group by d.id
Here is the thinking behind it: suppose document table has record A related to content(1, 2, 3, 4) and B related to (5, 6, 7, 8)
document content
A 1
2
3
4
B 5
6
7
8
a inner join with max(dateadded) will give you
document content max(dateadded)
A 1 1-1-2009...
A 2 1-1-2009...
A 3 1-1-2009...
A 4 1-1-2009...
B 5 2-1-2009...
B 6 2-1-2009...
B 7 2-1-2009...
B 8 2-1-2009...
after group by document id you will get
document content max(dateadded)
A 1 1-1-2009...
B 5 2-1-2009...
note: content id does not necessary match the id of the max dateadded