How to do the following - I made a sample request. Data was displayed, but for example in the column '1' - 10 identical values. That is, the conclusion I will have is such a column 1 f f f, etc.

How to display only 1 f, and if, for example, the value of a appears in the same column, display it as well.

  • four
    To select unique values, use the DISTINCT statement: SELECT DISTINCT name FROM users - etki
  • @Fike, make your comment a response - mountpoint
  • @mountpoint, the author has not yet confirmed that this is exactly what he needs, and I have an idea that a good answer should explain in detail what is happening in the code (as in SO) (and I am always lazy) I have nothing against , but I don’t think it is necessary - etki
  • @Fike, I think that in this case with DISTINCT you do not need to write a bunch of noodles. You clearly and clearly voiced a solution to the problem (I hope this is what the TC needs) - mountpoint

1 answer 1

There are two ways to get unique values ​​in the sample. Let there is a table tbl with a column name .

Grouping values

To group values, a GROUP BY is used, followed by a column name. A side effect of grouping is the fact that you only get the unique values ​​of the grouped field.

 SELECT name FROM tbl GROUP BY name 

The main purpose of the GROUP BY obtain groups of records for applying aggregate functions, so purists often criticize this approach for obtaining unique values.

Explicit request for unique values

To query for unique values, you can specify the keyword DISTINCT in front of the column name

 SELECT DISTINCT name FROM tbl