Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FREETEXT and COUNT

Posted on 2006-11-20
3
Medium Priority
?
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
ID: 17977687
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
ID: 17977707
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
ID: 17977773
Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

609 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