I have two separate queries on 2 different tables which I am trying to join into one query. Both tables are within the same schema.
I am trying to form a query which will return the forumid, threadid and subject of the most recent post in a forum. I can use the two queries I wrote below, but for the sake of efficiency I would prefer to use just one if possible.
The following are my queries:
1>
SELECT forumid,threadid
FROM threadtable
WHERE modifieddate = (select max(modifieddate) from threadtable);
2>
SELECT subject
FROM messsagetable
WHERE modifieddate = (select max(modifieddate) from messsagetable);
I have tried a few solutions but seem to be going round in circles. Any suggestions appreciated. Version is Postgres 8.1.
threadidin themessagetable?messagetableandthreadtable? e.G. does messagetable have a foreign key that connects it to an entry in threadtable?