SELECT 1 FROM FORUM_TOPICS WHERE EXISTS
(Select TOPIC_ID from FORUM_TOPICS T INNER JOIN FORUM_FORUM F ON T.FORUM_ID=F.FORUM_ID where F.F_TYPE = 2)
UNION
SELECT 1 FROM FORUM_REPLY WHERE EXISTS
(SELECT REPLY_ID from FORUM_REPLY R INNER JOIN FORUM_FORUM F ON R.FORUM_ID=F.FORUM_ID where F.F_TYPE = 2)
I think you've already given me what I need but I need to test it.
I want to get a recordset of all good (F_TYPE=0) or bad (F_TYPE=2) topics and replies. I want to loop through all these rows of topics and replies and process the words in each T_MESSAGE or R_MESSAGE. I wrote a function getWords which takes a string argument i.e. getWords(T_MESSAGE) and returns an array of all words along with their frequency. I want to loop through this array and adjust the forum_spam table accordingly i.e. new words (and frequency) will be inserted and existing words (which will adready have a frequency) will be updated with their new frequency.
Sorry for the confusion, I don't need to know if a word exists in the forum_topics or forum_reply tables, I just need to know if it exists on the forum_spam table. That bit is simple (even for me).
Is there a more efficient way of getting the count of all rows returned for this query other than executing it ?
Select T_MESSAGE from FORUM_TOPICS T INNER JOIN FORUM_FORUM F ON T.FORUM_ID=F.FORUM_ID where F.F_TYPE = 2
UNION
SELECT R_MESSAGE from FORUM_REPLY R INNER JOIN FORUM_FORUM F ON R.FORUM_ID=F.FORUM_ID where F.F_TYPE = 2
SELECT Sum(Result) FROM (
Select COUNT(TOPIC_ID) As Result from FORUM_TOPICS T INNER JOIN FORUM_FORUM F ON T.FORUM_ID=F.FORUM_ID where F.F_TYPE = 2
UNION
SELECT COUNT(REPLY_ID)As Result from FORUM_REPLY R INNER JOIN FORUM_FORUM F ON R.FORUM_ID=F.FORUM_ID where F.F_TYPE = 2
) As MyTable