Click here to Skip to main content
15,899,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

how to delete top ten row from the table
any query for that,please inform me.

thank & regards
vinay
Posted

Assuming your tablename has an id column :
SQL
delete from tablename where id in (select top 10 id from tablename)
 
Share this answer
 
Comments
Uday P.Singh 28-Oct-11 2:16am    
my 5!
Mehdi Gholam 28-Oct-11 2:23am    
Thanks
RaisKazi 28-Oct-11 3:02am    
Simple, short and correct! My 5!
Mehdi Gholam 28-Oct-11 4:45am    
Thanks
Toniyo Jackson 28-Oct-11 3:10am    
Correct but sub query will give performance problem. Check my easy answer. 5!
Try this:

SQL
DELETE 
FROM dbo.TableName
WHERE Primarykeyfieldname IN
(
	SELECT TOP 10 Primarykeyfieldname
	FROM dbo.TableName
)


hope it helps :)
 
Share this answer
 
Comments
RaisKazi 28-Oct-11 3:02am    
Simple, short and correct! My 5!
Uday P.Singh 28-Oct-11 3:04am    
thanks RaisKazi :)
Try this.
SQL
DELETE TOP(10) FROM table_name
 
Share this answer
 
Comments
RaisKazi 28-Oct-11 3:37am    
My 5! Yes this is better approach considering performance.
Toniyo Jackson 28-Oct-11 3:42am    
Thanks Rais :)
Bala Selvanayagam 28-Oct-11 3:38am    
Great, perfect solution my5
Toniyo Jackson 28-Oct-11 3:42am    
Thanks Bala :)
Mehdi Gholam 28-Oct-11 4:44am    
5'ed! delete top(x) is available in sql2005+
this link could help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900