Using SELECT DISTINCT in MYSQL

I did a lot of searching and really did not find the answer to my problem with MYSQL.

SELECT DISTINCT name, type, state, country FROM table 

Results in 1795 records

 SELECT DISTINCT name FROM table 

Results in 1504 reports

For each duplicate, "name" ... "type", "state", "country" do not match in each record.

Trying to figure out how to select the appropriate row for the name DISTINCT without checking them as DISTINCT or not

+6
sql mysql distinct
source share
2 answers
 SELECT name, type, state, country FROM table GROUP BY name; 

gotta do the trick.

+16
source share

If you need a different name, you must decide which of several values ​​may occur for each individual name that you want. For example, you may need minimum values ​​or values:

SELECT name, min(type), min(state), count(country) FROM table GROUP BY name

+1
source share

All Articles