If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How select Documents which contain more than 5 words

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-03-08, 07:52
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
How select Documents which contain more than n tag-specified words

Hello ALL,

I have a table contains words extracted from a few documents.

Code:
DocID         Word     Tag
1                Book     noun
1                Pen       noun
1                Pencil    noun

2                There     prep
2                Hand     noun
2                Have     verb

3                Oil         noun
3                Thorough    adv
3                Drive      verb

4                Red        adj
4                Blue        adj
4                Pike        adj
I would like to select those (noun or verb) records in the documents which contains more than or equal to two nouns or verbs. Actually I want the following result
Code:
DocID         Word     Tag
1                Book     noun
1                Pen       noun
1                Pencil    noun

2                Hand     noun
2                Have     verb

3                Oil         noun
3                Drive      verb
How to do this with a SQL query. Thanks

Last edited by cy163; 12-03-08 at 08:01.
Reply With Quote
  #2 (permalink)  
Old 12-03-08, 08:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
SELECT t.DocID
     , t.Word
     , t.Tag
  FROM daTable AS t
INNER
  JOIN ( SELECT DocID
           FROM daTable
          WHERE Tag IN ( 'noun','verb' )
         GROUP
             BY DocID
         HAVING COUNT(*) >1 ) AS d
    ON d.DocID = t.DocID
 WHERE t.Tag IN ( 'noun','verb' )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-03-08, 09:15
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
r937 thank you very much in deed. You always provide instant and helpful solutions.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On