Hej,
Jag försöker plocka ut den senaste posten is tabellen "replies" samt User id och User namn i tabellen "Users"
Problemet är att när jag öppnar sidan står den bara o tuggar o tuggar till jag får script.timeout!?
SELECT TOP 1 Threads.ThreadID, Replies.ReplyID, Replies.rDate, Users.userID, Users.uName FROM (((Forums INNER JOIN Threads ON Forums.ForumID = Threads.tForumID) INNER JOIN Replies ON Threads.ThreadID = Replies.rThreadID) INNER JOIN Users ON Replies.rUserID = Users.UserID) WHERE Forums.fGroupID = 1 ORDER BY Replies.rDate DESC
Nu har jag provat att tabort all joinarna utom en men det blir ingen skillnad?
Kolla den här sql
strSQL = "SELECT Groups.GroupID, Groups.gName, Groups.gActive, Groups.gOrder, Groups.gDescription, "
strSQL = strSQL & "(select Count(*) from Forums where fActive = true and fGroupID = Groups.GroupID) as cForum, "
strSQL = strSQL & "Forums.ForumID, "
strSQL = strSQL & "(select Count(Threads.ThreadID) from (Forums left join Threads on Forums.ForumID = Threads.tForumID) where Forums.fGroupID = Groups.GroupID) as cThread, "
strSQL = strSQL & "(select Count(Replies.ReplyID) from ((Forums left join Threads on Forums.ForumID = Threads.tForumID) left join Replies on Threads.ThreadID = Replies.rThreadID) where Forums.fGroupID = Groups.GroupID) as cReplies, "
[b]'strSQL = strSQL & "(select top 1 Replies.ReplyID from ((Forums inner join Threads on Forums.ForumID = Threads.tForumID) left join Replies on Threads.ThreadID = Replies.rThreadID) where Forums.fGroupID = Groups.GroupID order by Replies.rDate desc) as lastReplyID, "[/b]
strSQL = strSQL & "Threads.ThreadID, Threads.tUserID, Threads.tDate, "
strSQL = strSQL & "Users.UserID, Users.uName "
strSQL = strSQL & "FROM (((Groups "
strSQL = strSQL & "LEFT JOIN Forums "
strSQL = strSQL & "ON Groups.GroupID = Forums.fGroupID) "
strSQL = strSQL & "LEFT JOIN Threads "
strSQL = strSQL & "ON Forums.ForumID = Threads.tForumID) "
strSQL = strSQL & "LEFT JOIN Users "
strSQL = strSQL & "ON Threads.tUserID = Users.UserID) "
strSQL = strSQL & "WHERE Groups.gActive = true AND Forums.fActive = true "
strSQL = strSQL & "ORDER BY Groups.gOrder DESC, Threads.tDate DESC"
Set objRS = Conn.Execute(strSQL)
Den funkar om jag tarbort den fetmarkerade raden. Men med den försöker jag hämta "ReplyID" för den senaste posten i tabellen "Replies". Fattar inte vad som går fel?
Det jag helst skulle villja få fram med den är den senaste posten i tabellerna "Threads" eller "Replies" tillsammans med resp. user ID, User name. Som det är nu måste jag hämta den infomationen i själva loopen sedan med en separat sql-sats :( Men i detta fallet finns det väl inga alternativ(?)