MySQL: SELECT UNIQUE VALUE

前端 未结 4 2035
天涯浪人
天涯浪人 2020-12-16 11:09

In my table I have several duplicates. Ineed to find unique values in mysql table column.

SQL

SELECT column FROM table
WHERE column          


        
相关标签:
4条回答
  • 2020-12-16 11:15

    try this > select distinct (columnName) from table

    0 讨论(0)
  • 2020-12-16 11:35

    Try to use DISTINCT like this:

    SELECT DISTINCT mycolumn FROM mytable
    

    EDIT:

    Try

    select mycolumn, count(mycolumn) c from mytable
    group by mycolumn having c = 1
    
    0 讨论(0)
  • 2020-12-16 11:36

    Here is the query that you want!

    SELECT column FROM table GROUP BY column HAVING COUNT(column) = 1
    

    This query took 00.34 seconds on a data set of 1 Million rows.

    Here is a query for you though, in the future if you DO want duplicates, but NOT non-duplicates...

    SELECT column, COUNT(column) FROM table GROUP BY column HAVING COUNT(column) > 1
    

    This query took 00.59 seconds on a data set of 1 Million rows. This query will give you the (column) value for every duplicate, and also the COUNT(column) result for how many duplicates. You can obviously choose not to select COUNT(column) if you don't care how many there are.

    You can also check this out, if you need access to more than just the column with possible duplicates... Finding duplicate values in a SQL table

    0 讨论(0)
  • 2020-12-16 11:38

    Try this one:

    SELECT COUNT(column_name) AS `counter`, column_name 
    FROM tablename 
    GROUP BY column_name 
    WHERE COUNT(column_name) = 1
    

    Have a look at this fiddle: http://sqlfiddle.com/#!9/15147/2/0

    0 讨论(0)
提交回复
热议问题