6
For example have in the table the values: green, red, blue, blue, pink, pink, pink, yellow. I would need to return from the colors table only once the blue and the pink. Is there any way to do this?
6
For example have in the table the values: green, red, blue, blue, pink, pink, pink, yellow. I would need to return from the colors table only once the blue and the pink. Is there any way to do this?
16
Use DISTINCT
will return without repeating:
SELECT DISTINCT cor FROM Cores;
another unorthodox solution would be to use GROUP BY:
SELECT cor FROM Cores GROUP BY cor;
That’s right, I’d forgotten.
I believe that the GROUP BY
be better, I’ve had absurd performance improvements while changing the DISTINCT
by a GROUP BY
in the same queries
. Inclusive had a query
which took approximately 30 seconds to run, and her process on the process list was at least 28 seconds like "Removing Duplicity" basically, so I took the DISTINCT
and put a GROUP BY
at the end, and 30 seconds dropped to 0.8 seconds.
6
SELECT DISTINCT cor, outra_coluna_se_quiser FROM cores;
I put in the Github for future reference.
The secret there is the DISTINCT
. It selects only rows in a single way, without repeating the column value.
thank you had forgotten this!
2
SELECT DISTINCT * FROM cores
You can also use a GROUP BY to group colors:
SELECT DISTINCT * FROM cores GROUP BY cor
I’m sorry, but it’s not exactly what was answered by Ricardo?
True, I’m new here I’m still learning to use...
Start by doing the [tour] then, there gives an overview of how the site works.
Thanks! I’ll do yes :]
Browser other questions tagged mysql sql query
You are not signed in. Login or sign up in order to post.
Accessed 26 thousand times and with three upvotes only.
– CypherPotato