MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 11th, 2000, 10:57 AM
RyanP
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
i would like to count a column and only display records where the count is greater than 1

i tried something like:

SELECT COUNT(foo) AS bar
FROM tbl
WHERE bar > 1

but that didn't work

any ideas?

Reply With Quote
  #2  
Old October 11th, 2000, 01:04 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
I don't get what you are saying. count() returns a count of records. you can't use it to reference a record since it's not related to any one record.

Reply With Quote
  #3  
Old October 11th, 2000, 01:35 PM
RyanP
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
****, i don't get what i was saying either URL

i should have said that i'm trying to group records by how many duplicates there are and i only want to see records that have more than one occurance

so i tried to use something like:

SELECT Name, COUNT(Name) AS foo
FROM tbl
WHERE foo > 1
GROUP BY Name

but that didn't work, i assume that you just can't use aggregates in WHEREs

any known workaround?

hope that clears it up, sorry for the confusion

Reply With Quote
  #4  
Old October 11th, 2000, 04:54 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
You'd have to use the count(*) in the where and I'm not even sure if that would work:

select name from tbl where count(*)>1 group by name;

give it a try. If you have a unique identifier you could join the table to itself:

select t1.name,t1.id,t2id from tbl t1,tbl t2 where t1.name=t2.name and t1.id!=t2.id;


Reply With Quote
  #5  
Old October 11th, 2000, 06:34 PM
RyanP
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
i get a "ERROR 1111: Invalid use of group function" whenever i try to use an aggregate function in a WHERE

but joining the table on itself worked great, thanks for the idea

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SQL -- Possible to use COUNT() column in WHERE?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT