simple question about group by and custom groups Imagine a MySQL table that only has 2 columns: an id and a name of a color.

With this query, I know how many id's I have for each color:

SELECT color_name, count(id) FROM color_table GROUP BY (color_name)

red:    10 
blue:   5 
yellow: 3
green:  1


My question is, is there a way I can specify to the "group by" some custom groups?? I mean, is there a query that results in this:

red: 10
colors different than red: 9
Directly using GROUP BY, no. You can still get the results you want, though, and there are many ways to accomplish it. Such as UNION:

SELECT 'red', COUNT(*) FROM color_table WHERE color_name='red'
UNION
SELECT 'colors different than red', COUNT(*) FROM color_table WHERE color_name &lt;&gt; 'red'