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 to query for words appearing in ONLY one doc

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-09, 09:39
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
how to query for words appearing in ONLY one doc

Hello ALL,

I have a table like
Code:
tlb

ClassID  Class        Word           Freq
1           Sports     basketball        3
1           Sports     Football           2
1           Sports     Volleyball         3

2          Education  Basketball      2
2          Education  Music             1

3          Art            Picture           3 
3          Art            Football          3
I would like to find words which are unique for classes(i.e., words which appear only in one class), e.g.

Code:
Sports          Volleyball
Education       Music
Art              Picture
I figure out the following query statement
Code:
SELECT ID, Class, Word FROM tlb GROUP BY Word HAVING COUNT(Class) = 1;
but i am not sure. please help me.

Last edited by cy163; 04-23-09 at 09:52.
Reply With Quote
  #2 (permalink)  
Old 04-23-09, 10:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
SELECT Word FROM tlb GROUP BY Word HAVING COUNT(*) = 1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-23-09, 19:11
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
Thanks r937.

i did not know what is the difference between COUNT(*) and COUNT(ColumnName) in a query statement. could you please explain this for me. Thanks.
Reply With Quote
  #4 (permalink)  
Old 04-23-09, 19:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
did you check da manual? it's pretty clear on the difference

COUNT(*) counts rows

COUNT(ColumnName) counts non-NULL values
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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