how to bring the records and group the repeated and also show?

0

this is my BD on phpmyadmin

commercer_id | commerce_district|
1              abacay
2              abacay
3              ahuac
4              alto de la alianza
5              alto de la alianza
6              amarilis

This is my query, but I bring all the records repeated and with distinctly the same, I would like to ask you to bring me all the records but to group the repeated ones and just bring me only one of the repeated ones that are not repeated . I'm new to BD

SELECT 
commerce_district, commerce_id FROM commerc 
ORDER BY commerc.commerce_distric ASC
    
asked by ivan fuenmayor 19.10.2018 в 16:04
source

1 answer

0

You can use the GROUP BY clause

SELECT commerce_district, COUNT(commercer_id) AS [assigned_id]
FROM commerc
GROUP BY commerce_district
ORDER BY COUNT(commercer_id) ASC

As in your case some districts are assigned more than one id what you should do is count the id , grouping by district, and in this way shows you what you need.

commerce_district | assigned_id |
ahuac               1
amarilis            1
abacay              2
alto de la alianza  2
    
answered by 19.10.2018 в 20:01