I have a table with the following structure:
| animal | color |
|--------|-------|
| dog | black |
| dog | white |
| cat | white |
| dog | black |
| mouse | grey |
I now want to get the distinct values of each column.
Just doing:
SELECT DISTINCT animal, color from tab1
Would just omit the 2nd occurrence of dog - black:
| animal | color |
|--------|-------|
| dog | black |
| dog | white |
| cat | white |
| mouse | grey |
But what I want is some structure that looks as follows:
animal: dog, cat, mouse
color: black, white, grey
My approach would just be to perform several SELECT queries:
- SELECT DISTINCT animal from tab1
- SELECT DISTINCT color from tab1
And then just combine those results into an array with PHP.
But is there a quicker way, maybe with just one query?