Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: How to get rows repeated x times

Tags:

php

mysql

Which MySQL query should I use to get just rows repeated X times?

Example (stupid one ^^):

John likes apples.
Dave likes apples.
Bough likes bananas.
Light likes apples.
Wiky likes bananas.

I want a query that returns just fruits liked by 3 people (apples in my example). Cheers!

like image 337
Nadjib Mami Avatar asked Apr 23 '11 16:04

Nadjib Mami


1 Answers

I want a query that returns just fruits liked by 3 people (apples in my example)

Try this:

SELECT fruit_name FROM `table` group by fruit_name having count(fruit_name)>=3;
like image 182
Harry Joy Avatar answered Sep 20 '22 10:09

Harry Joy