Question: I'm trying to build a Delete query for the below script which has multiple columns in group by.

```
select Test_1,Test_2,Test_3,Test_4,Test_5,Test_6,Test_7,Test_8,Test_9,
Test_10,Test_11,Test_12,Test_13,Test_14,Test_15,Test_16,Test_17,Test_18,Test_19,Test_20,
Test_21,Test_22,Test_23,Test_24,Test_25,Test_26,Test_27,Test_28,Test_29,Test_30 from Test_Table
where PROS_Test='236458' 
group by Test_1,Test_2,Test_3,Test_4,Test_5,Test_6,Test_7,Test_8,Test_9,
Test_10,Test_11,Test_12,Test_13,Test_14,Test_15,Test_16,Test_17,Test_18,Test_19,Test_20,
Test_21,Test_22,Test_23,Test_24,Test_25,Test_26,Test_27,Test_28,Test_29,Test_30
having count(*)>1 

```

The total count for the select query is `102100`, I need the delete query for the same.

Answer: 
Try `delete` statement with subquery: 

```
delete tt 
from (
    select row_number() over (partition by Test_1,Test_2,Test_3,Test_4,Test_5,Test_6,Test_7,Test_8,Test_9,
    Test_10,Test_11,Test_12,Test_13,Test_14,Test_15,Test_16,Test_17,Test_18,Test_19,Test_20,
    Test_21,Test_22,Test_23,Test_24,Test_25,Test_26,Test_27,Test_28,Test_29,Test_30 order by Test_1) rn
    from Test_Table
    where PROS_Test='236458'
) tt where rn > 1

```
you can create a cte with your query and use it in the delete command:

```
with cte as (
    select Test_1,Test_2,Test_3,Test_4,Test_5,Test_6,Test_7,Test_8,Test_9,
    Test_10,Test_11,Test_12,Test_13,Test_14,Test_15,Test_16,Test_17,Test_18,
    Test_19,Test_20,Test_21,Test_22,Test_23,Test_24,Test_25,Test_26,
    Test_27,Test_28,Test_29,Test_30 from Test_Table
    where PROS_Test='236458' 
    group by Test_1,Test_2,Test_3,Test_4,Test_5,Test_6,Test_7,Test_8,Test_9,
    Test_10,Test_11,Test_12,Test_13,Test_14,Test_15,Test_16,Test_17,Test_18,
    Test_19,Test_20,Test_21,Test_22,Test_23,Test_24,Test_25,Test_26,
    Test_27,Test_28,Test_29,Test_30
    having count(*) > 1 
)
delete t
from Test_Table as t
INNER JOIN cte as c ON t.Test_1 = c.Test_1 ...

```

And all the conditions you need besides the Test\_1 matching.