Been doing a lot of searching and haven't really found an answer to my MYSQL issue.
SELECT DISTINCT name, type, state, country FROM table
Results in 1,795 records
SELECT DISTINCT name FROM table
Results in 1,504 records
For each duplicate "name"... "type", "state", "country" aren't matching in each record.
Trying to figure out how to SELECT the associated row to the DISTINCT name, without checking them for being DISTINCT or not
To get unique or distinct values of a column in MySQL Table, use the following SQL Query. SELECT DISTINCT(column_name) FROM your_table_name; You can select distinct values for one or more columns. The column names has to be separated with comma.
Introduction to MySQL DISTINCT clause When querying data from a table, you may get duplicate rows. To remove these duplicate rows, you use the DISTINCT clause in the SELECT statement. In this syntax, you specify one or more columns that you want to select distinct values after the SELECT DISTINCT keywords.
The DISTINCT keyword in the SELECT clause is used to eliminate duplicate rows and display a unique list of values. In other words, the DISTINCT keyword retrieves unique values from a table.
Introduction to SQL DISTINCT operator Note that the DISTINCT only removes the duplicate rows from the result set. It doesn't delete duplicate rows in the table. If you want to select two columns and remove duplicates in one column, you should use the GROUP BY clause instead.
SELECT name, type, state, country FROM table GROUP BY name;
should do the trick.
If you want distinct name, you must decide which of the multiple values that may occur for each distinct name you want. For example, you may want minimals, or counts:
SELECT name, min(type), min(state), count(country) FROM table GROUP BY name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With