SQL - similar data in column

前端 未结 3 691
野的像风
野的像风 2021-01-20 15:52

Is there any way to find similar results in column. Example:

I want query return from table data without 4 green tree because there is no similar data to g

3条回答
  •  一个人的身影
    2021-01-20 16:19

    As Gar rightfully commented, you have to define what do you mean by "similarity". But if all you need is just some fixed number (8 in your example) of equal characters, you can do the following :

    create table myTest
    (
        id int,
        name varchar(20)
    );
    
    insert into myTest values(1, 'blue car');
    insert into myTest values(2, 'red doll');
    insert into myTest values(3, 'blue cars');
    insert into myTest values(4, 'green tree');
    insert into myTest values(5, 'red dolly');
    
    select left(name,8), count(*) 
    from myTest 
    group by left(name,8) 
    having count(*) > 1;
    

提交回复
热议问题