PDA

View Full Version : Problem with threadcount...


Kaitlyn2004
11-13-2007, 06:03 PM
This is the threadcount query in forumdisplay:

SELECT COUNT( * ) AS threads, SUM( IF( thread.lastpost >1194966616
AND OPEN <>10, 1, 0 ) ) AS newthread
FROM vb3thread AS thread
WHERE forumid =11
AND sticky =0
AND visible
IN ( 0, 1, 2 )

I have another table, vb3tags ... has tag, and threadid columns. If I want to search multiple tags (AND) I might do something like this (off top of head):

SELECT COUNT( * ) AS threads, SUM( IF( thread.lastpost >1194966616
AND OPEN <>10, 1, 0 ) ) AS newthread
FROM vb3thread AS thread, vb3tags AS tags
WHERE forumid =11
AND sticky =0
AND visible
IN ( 0, 1, 2 )
AND tags.threadid = thread.threadid
AND tags.Tag IN ('tag1', 'tag2')
GROUP BY thread.threadid
HAVING COUNT(thread.threadid) = 2

Of course, that doesn't work. Can anyone help me along with this? My method works for everything EXCEPT the counting of threads..

ALL help greatly appreciated

Analogpoint
11-13-2007, 07:04 PM
What is it exactly that you want to accomplish?

Kaitlyn2004
11-13-2007, 07:20 PM
Take the original count query but only count the threads which have a tag of TAG1 and TAG2, which is from vb3tags that has a threadid column...

Analogpoint
11-13-2007, 07:41 PM
Ok, gotcha. I'm not an SQL guru, so I probably won't be of much help. But you should be able to accomplish that with an inner join.