Advanced query question?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Owe Blomqvist
Forum Commoner
Posts: 33
Joined: Wed Oct 16, 2002 2:27 pm

Advanced query question?

Post by Owe Blomqvist »

Hi.
I´m stuck..... again.. :(

I´m trying the query the mysql db to get all fields inside a column that are listed more than five times.
For each "5 or more of the same" it should output one hit.
I have no clue how to do this & i can´t find anywhere how to do it either.
Direction pointers would be highly appreciated.

The column below should result in 2, since only mouse & dog appear five times or more.

Thank you in advance,
Best Regards,
Owe Blomqvist

example column:
_________
| CAT |
| CAT |
| CAT |
| MOUSE |
| MOUSE |
| MOUSE |
| MOUSE |
| MOUSE |
| MOUSE |
| DOG |
| DOG |
| DOG |
| DOG |
| DOG |
|________|
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post by samscripts »

Hi, try this one:

SELECT count( your_column_name ) as total, column_name, any_other_fields
FROM your_table
GROUP BY your_column_name
HAVING total > 4

hope this helps.

sam
Owe Blomqvist
Forum Commoner
Posts: 33
Joined: Wed Oct 16, 2002 2:27 pm

Post by Owe Blomqvist »

Is that all?
I have been pulling my hair over this one.
Thank you very much for your help.
Post Reply