I have a MySQL table like this:
MYTABLE |-------------| | ID | COLOR | |----|--------| | 01 | WHITE | | 01 | BLACK | | 01 | YELLOW | | 02 | RED | | 02 | BLUE | | 02 | YELLOW | | 03 | BLACK | | 03 | BLUE | | 03 | YELLOW | |-------------| When I want to get all colors from an ID, I execute this query:
SELECT `COLOR` FROM `MYTABLE` WHERE `ID` = 2 RESULT |--------| | COLOR | |--------| | RED | | BLUE | | YELLOW | |--------| How can I also get how many times each color exist in table?
What query I have to execute to get the following results?
HOW CAN I GET THIS? |----------------| | COLOR | COUNT | |--------|-------| | RED | 1 | | BLUE | 2 | | YELLOW | 3 | |----------------| Thanks in advance.