Solved

FREETEXT and COUNT

Posted on 2006-11-20
3
371 Views
Last Modified: 2008-03-10
Hi I have a table that contains forum messages:

messageID       topicID       messageText

     1                    1           apple
     2                    1           orange
     3                    2           grape
     4                    1           cherry
     5                    3           peach

I have a query to get all the messages that contain the word "apple":

            SELECT * FROM tblMessages WHERE FREETEXT (messageText, 'apple');

This works fine but I would also like a count of how many other messages there are associated with the same topicID as the records returned by the the above query.  This is how I would like the result set to be:

messageID      topicID         messageText       numMsgs
      1                  1                 apple                   3

Is this possible?
0
Comment
Question by:champ_010
3 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 125 total points
Comment Utility
SELECT
    tm.messageId,
    tm.topicId,
    (select count(*) from tblMessages as tm2 where tm2.topicId = tm.topicId) as numMsg
FROM
    tblMessages as tm
WHERE
    FREETEXT (tm.messageText, 'apple');
0
 
LVL 28

Expert Comment

by:imran_fast
Comment Utility
SELECT
    tm.messageId,
    tm.topicId,
    No_Of_Msg
FROM
    tblMessages as tm
inner join (select count(*) No_Of_Msg , topicId from tblMessages group by topicId ) TC
on tc.topicId = tm.topicId
WHERE
    FREETEXT (tm.messageText, 'apple')
go
0
 
LVL 1

Author Comment

by:champ_010
Comment Utility
Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now