How to make a select in the bank not to bring repeated values?

Asked

Viewed 71,632 times

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?

  • Accessed 26 thousand times and with three upvotes only.

3 answers

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

2

SELECT DISTINCT * FROM cores

You can also use a GROUP BY to group colors:

SELECT DISTINCT * FROM cores GROUP BY cor
  • 2

    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

You are not signed in. Login or sign up in order to post.