Hey, I have 2 tables in PostgreSql:
1 - documents: id, title
2 - updates: id, document_id, date
and some data:
documents:
| 1 | Test Title |
updates:
| 1 | 1 | 2006-01-01 |
| 2 | 1 | 2007-01-01 |
| 3 | 1 | 2008-01-01 |
So All updates are pointing to the same document, but all with different dates for the updates.
What I am trying to do is to do a select from the documents table, but also include the latest update based on the date.
How should a query like this look like? This is the one I currently have, but I am listing all updates, and not the latest one as the one I need:
SELECT * FROM documents,updates WHERE documents.id=1 AND documents.id=updates.document_id ORDER BY date
To include; The reason I need this in the query is that I want to order by the date from the updates template!
Edit: This script is heavily simplified, so I should be able to create a query that returns any number of results, but including the latest updated date. I was thinking of using a inner join or left join or something like that!?