Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-04-06 : 16:49:21
|
| I'm working on a basic forum and I am trying to show the "Topic Starter"This query is working nicely, but without the AuthorID of the topic starter.SELECT Subject, NoOfViews, TopicID, B.PostsFROM OI_Topic ALEFT OUTER JOIN( SELECT Count(TopicID) As Posts, TopicID FROM OI_Thread GROUP BY TopicID) AS BON A.TopicID = B.TopicIDWHERE ForumID = '1'Now, I am trying to get the 1st Date of the post, this will be the topic starter. However, when I do a SELECT TOP 1, it only selects the AuthorID for one topic, which makes sense. Is it possible to show the topic starter? If you go to http://rockenbach.net/topic.gifYou can see the query in rows in EM.SELECT Subject, NoOfViews, TopicID, B.Posts, C.AuthorIDFROM OI_Topic ALEFT OUTER JOIN( SELECT Count(TopicID) As Posts, TopicID FROM OI_Thread GROUP BY TopicID) AS BON A.TopicID = B.TopicIDLEFT OUTER JOIN( SELECT TOP 1 AuthorID, TopicID FROM OI_Thread ORDER BY messagedate ASC) AS CON A.TopicID = C.TopicIDWHERE ForumID = '1' |
|
|
rfrancisco
Yak Posting Veteran
95 Posts |
Posted - 2005-04-06 : 17:13:14
|
| Try changing this query:SELECT TOP 1 AuthorID, TopicIDFROM OI_ThreadORDER BY messagedate ASCintoSELECT TopicID, AuthorIDFROM OI_Thread AWHERE messagedate = (SELECT MIN(messagedate) FROM OI_Thread BWHERE A.TopicID = B.TopicID) |
 |
|
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-04-06 : 18:22:22
|
| WOW! Perfect! That is just what I needed. Thank you, I learned something new. |
 |
|
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-04-09 : 19:37:23
|
| I need help again, this is almost the same deal as before. This the first page of the forum and I am trying to show the last post. There are 3 forums, so there should only be 3 rows returned (by the most recent date.Here is my SQL. If you go to http://rockenbach.net/topic.gif you can see a screen print of EMSELECT A.ForumID, A.ForumName, A.ForumDescription, A.DateStarted, A.NoOfTopics, A.NoOfPosts, C.MessageDateFROM OI_Forum ALEFT OUTER JOIN(SELECT TopicID, ForumID, LastEntryDateFROM OI_Topic AWHERE LastEntryDate = (SELECT MAX(LastEntryDate) FROM OI_Topic BWHERE A.TopicID = B.TopicID)) AS BON A.ForumID = B.ForumIDLEFT OUTER JOIN(SELECT UserID, TopicID, MessageDateFROM OI_Thread AWHERE MessageDate = (SELECT MIN(messagedate) FROM OI_Thread BWHERE A.TopicID = B.TopicID))AS CON B.TopicID = C.TopicID |
 |
|
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-04-10 : 08:45:33
|
| I think I have figured it on my own. After breaking it down into smaller chunks I see the problem. The one you originally helped with works perfectly. I was trying to use your technique to a similiar page ( the main forum page) This is working for me so far. SELECT A.ForumID, A.ForumName, A.ForumDescription, A.NoOfTopics, A.NoOfPosts, B.LastEntryDateFROM OI_Forum ALEFT OUTER JOIN(SELECT TopicID, ForumID, LastEntryDateFROM OI_Topic AWHERE LastEntryDate = (SELECT MAX(LastEntryDate) FROM OI_Topic BWHERE A.ForumID = B.ForumID)) AS BON A.ForumID = B.ForumID |
 |
|
|
|
|
|
|
|