Learn Microsoft Sql Server
Learning is never ending process
Thursday, 20 June 2019
Tuesday, 18 June 2019
Wednesday, 1 May 2019
Delete rows with subquery
create table #test(id int,name varchar(200))
insert into #test
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shrikant'
union all
select 1,'Shrikant'
alter table #test
add Row_id int identity(1,1)
--with subquery
delete a from #test a
where a.Row_id not in ( select min (Row_id) from #test group by Id,name)
select * from #test
insert into #test
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shabash '
union all
select 1,'Shrikant'
union all
select 1,'Shrikant'
alter table #test
add Row_id int identity(1,1)
--with subquery
delete a from #test a
where a.Row_id not in ( select min (Row_id) from #test group by Id,name)
select * from #test
Friday, 9 March 2018
Thursday, 22 February 2018
Wednesday, 10 January 2018
Wednesday, 3 January 2018
Saturday, 30 December 2017
Wednesday, 20 December 2017
Subscribe to:
Posts (Atom)
-
When SQL Server executes a query it uses a query plan to determine how to access data and complete the query. SQL Server offers DBAs and d...