One occurrence of a word only - Delete repeated rows

  • There are loads of threads on how to do this, if you'd care to search for them. You need to do something like this (not tested):

    WITH MyWords AS (

    SELECT

    ROW_NUMBER() OVER (PARTITION BY Word ORDER BY Word) AS seq

    ,Word

    FROM

    Words

    )

    DELETE FROM

    MyWords

    WHERE

    seq > 1

    John

  • Create table Fruits

    (Fruit varchar(10))

    insert into Fruits

    select 'apple' Union all

    select 'apple' Union all

    select 'grapes' Union all

    select 'banana' Union all

    select 'grapes' Union all

    select 'blueberry' Union all

    select 'grapes' Union all

    select 'blueberry' Union all

    select 'apple' Union all

    select 'plum' Union all

    select 'plum' Union all

    select 'blueberry' Union all

    select 'banana' Union all

    select 'blueberry' Union all

    with cte

    As

    (

    select Row_number() over ( partition by Fruit order by Fruit desc) as id,Fruit

    From Fruits

    )

    Delete From cte where id >1

    select * from Fruits

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply