Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL query doubts

Author  Topic 

rajeshskpm
Starting Member

10 Posts

Posted - 2009-01-30 : 04:50:53
suppose a table contains 500 rows. i want to delete 13th,14th,15th rows in a table. how to do this using single query? please reply

rajesh

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-30 : 04:52:25
If the table contains a identity column or primary key column then

delete from table
where primarykeycol in ( 13,14,15)
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-30 : 04:52:31
if u dont have primarycolumn,
use row_number() it is easy for u
Go to Top of Page

rajeshskpm
Starting Member

10 Posts

Posted - 2009-01-30 : 04:54:53
plese write full query

rajesh
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-30 : 04:59:57
delete s from (select row_number() over( order by id)as rid,* from emp)s where rid in (13,14,15)
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-30 : 05:01:17
delete table where primarycol in ( 13,14,15)

(or)

delete t from
( select *,row_number() over ( partition fieldname order by fieldname ) as rn from urtable ) t
where t.rn in (13,14,15)
Go to Top of Page
   

- Advertisement -