Reputation: 67
Is it possible to this?I have a table with two rows and 1 column.Both rows have same value.no primary key is there.can we delete 1 row?
Upvotes: 0
Views: 91
Reputation: 4934
You can get fancy and use cte to delete one but if they are the same value (and the table is as simple as you're describing it), you can also delete both and add one back. Much simpler.
Surrogate Key anyone?
Upvotes: 0
Reputation: 62851
Here's one way to do it with ROW_NUMBER()
and a common table expression
:
with cte as (
select *,
row_number() over (partition by id order by id) rn
from yourtable)
delete from cte
where rn = 1;
Upvotes: 1
Reputation: 5957
you can do this using RANK() function.
or you can use TOP keyword.
Upvotes: 0