Hi,
I am creating a threaded email database. I have three tables - Threads, Messages and Users.
The objective is to show all threads with unread messages and who the last message was posted by for each thread.
For this example the database knows I am logged in with UserID of 1. My Messages table has a field called AuthorID and my Users table has a field called UserID, FirstName and Surname.
What I am hoping to do is once I've got the maximum MessageID value is to be able to retrieve the AuthorID value and then do a join with the Users table on that value.
Is it possible to do this all in a single query?
Thanks very much
Ed
SELECT "M" AS Category, ThreadID, Title,
(SELECT COUNT(*)
FROM Messages
WHERE Messages.ThreadID=Threads.ThreadID AND
Messages.NotReadBy LIKE '%;1;%') AS NewMessages,
(SELECT MAX(MessageID)
FROM Messages
WHERE ThreadID=Threads.ThreadID) AS LatestMessageID
FROM Threads
WHERE Threads.Recipients LIKE '%;1;%';
I am creating a threaded email database. I have three tables - Threads, Messages and Users.
The objective is to show all threads with unread messages and who the last message was posted by for each thread.
For this example the database knows I am logged in with UserID of 1. My Messages table has a field called AuthorID and my Users table has a field called UserID, FirstName and Surname.
What I am hoping to do is once I've got the maximum MessageID value is to be able to retrieve the AuthorID value and then do a join with the Users table on that value.
Is it possible to do this all in a single query?
Thanks very much
Ed
SELECT "M" AS Category, ThreadID, Title,
(SELECT COUNT(*)
FROM Messages
WHERE Messages.ThreadID=Threads.ThreadID AND
Messages.NotReadBy LIKE '%;1;%') AS NewMessages,
(SELECT MAX(MessageID)
FROM Messages
WHERE ThreadID=Threads.ThreadID) AS LatestMessageID
FROM Threads
WHERE Threads.Recipients LIKE '%;1;%';