Page 1 of 1

Advanced query question?

Posted: Fri Nov 01, 2002 1:02 pm
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 |
|________|

Posted: Fri Nov 01, 2002 4:10 pm
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

Posted: Sat Nov 02, 2002 12:15 am
by Owe Blomqvist
Is that all?
I have been pulling my hair over this one.
Thank you very much for your help.