jeudi 31 mars 2016

Sqlite: Fetching records where 1 column exists more than once

I have a table that looks like this:

+---------+--------+
|  Food   | Color  |
+---------+--------+
| apple   | green  |
| banana  | yellow |
| salad   | green  |
| lemon   | yellow |
| coconut | brown  |
+---------+--------+

Based on the Color column, I would like to fetch those records where the Color column exists more than once.

In my example, the record apple, banana, salad and lemon should be fetched, but not coconut (because the color brown exists only once).

But I am not sure what the select statement would be.

I was thinking about something like SELECT * FROM mytable WHERE COUNT(color) > 1, but this is not right, I think.

Aucun commentaire:

Enregistrer un commentaire