There is a filter, in it the "Area" field, you need to list all the areas that are in the database, but in such a way that they do not repeat.

For example: we have 5 entries. The first field has “district” - 1, the second has 2, the third has 2, the fourth has 2 and the fifth has 7. The filter should have the following list: District {1,2,7}

I can not understand how not to display duplicate fields. In php beginner, I know few functions, so do not scold.

    1 answer 1

    There are two ways to get unique values ​​from a table, the first is to specify the DISTINCT keyword near the field to be extracted.

     SELECT DISTINCT distinct_id FROM tbl; 

    The second is to group by the distinct_id field using the GROUP BY keyword

     SELECT distinct_id FROM tbl GROUP BY distinct_id; 

    In both cases, you get a sample of only unique values ​​of the distinct_id field.

    • And for what the second way? - D-side
    • 2
      @ D-side In general, it is extremely convenient, although some SQL purists believe that you should not use GROUP BY only to get unique values, since groups are not actually used. Although GROUP BY seems to me more readable and logical than DISTINCT, which not everyone remembers. - cheops