SQL: Getting Forum Topics 1 per User? - Posted (2177 Views)
Average Member
SiSL
Posts: 671
671
Is there an easy way of like getting latest x number of topics but only 1 topic per author of topic or instead of author not having same title of topics (like spammed ones)? Like not gettings "SiSL"'s 3 topics if he opened 3 of last 10 topics but 1 topic from SiSL and rest 1 topic per author... with Topic ID's and such for SQL Server?




 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Snitz Forums Admin
ruirib
Posts: 26364
26364
This was fun, now to get back to work wink. Of course, I am hoping no one noticed that I contradicted myself and ended up solving it all with a very, very, simple (tongue) SQL statement.
Posted
Forum Admin
HuwR
Posts: 20611
20611
well, to be honest four nested selects isn't exactly simple smile
Posted
Snitz Forums Admin
ruirib
Posts: 26364
26364
Originally posted by HuwR
well, to be honest four nested selects isn't exactly simple smile
It's not simple ?!! bigsmiletonguecoolevil
I promise I wrote them one at a time wink.
Posted
Forum Admin
HuwR
Posts: 20611
20611
I still think my first attempt was the simplesttongue I just should have dropped the #TempTopics table after doing the select smile
Posted
Snitz Forums Admin
ruirib
Posts: 26364
26364
From an execution point of view, I tested both ways with a database from a live Snitz forum and your option had a higher subtree cost (0,8 vs. 3.17) and a higher number of scans and logical reads (rather big difference here). Probably a disadvantage on a high traffic forum.
I had performed a similar comparison before, with Snitz too (query performance has always been of interest to me) and using derived tables wasn't actually faster than using temporary tables, probably because the number of records involved was much higher. I thought it was interesting to compare it in this situation.
This is fun, but I have already spent 2 or 3 hours with this. I better go do something more boring smile.
Posted
Forum Admin
HuwR
Posts: 20611
20611
smile yes, I ought to finish what I was doing beore getting side tracked.
You Must enter a message