Home > Enterprise >  how to remove rows that are related to same values
how to remove rows that are related to same values

Time:06-20

how do I turn this:

|  ID  | LETTER 
----------------     
|  1   |    A      
|  2   |    B            
|  3   |    B       
|  4   |    C       
|  5   |    D       
|  6   |    D      
|  7   |    F       
|  8   |    A    

On this:

|  ID  | LETTER 
----------------            
|  4   |    C                  
|  7   |    F       

CodePudding user response:

There are multiple ways to solve this problem, one possible way is -

SELECT
    *
FROM
    t_system_log;

SELECT
    t_table.*
FROM
    t_table,
    (
    SELECT
        letter
    FROM
        t_table
    GROUP BY
        letter
    HAVING
        count(letter) = 1) AS t_unique
WHERE
    t_table.letter = t_unique.letter
;

My Fiddle

CodePudding user response:

I'm using SQL 5.6, If the table name is t_name, Then simplest query to remove rows that are related to same values: *

SELECT * FROM t_name Group by LETTER having count(LETTER)=1;

  • Related