Deletion

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 2
Reputation: arunachalamsa is an unknown quantity at this point 
Solved Threads: 0
arunachalamsa arunachalamsa is offline Offline
Newbie Poster

Deletion

 
0
  #1
Jun 5th, 2006
how to delete nth row of a table through sql query?

please say me

thanks,
Arunachalam
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Deletion

 
0
  #2
Jun 5th, 2006
me
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Deletion

 
0
  #3
Jun 5th, 2006
sorry, couldn't resist. Will need table schema to answer your question
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 2
Reputation: arunachalamsa is an unknown quantity at this point 
Solved Threads: 0
arunachalamsa arunachalamsa is offline Offline
Newbie Poster

Re: Deletion

 
0
  #4
Jun 6th, 2006
what i meant in the question is delete based on row number..

if there are 10 row in a table, query should be such that i can delete 8th row through one query irrespective of the Table Attributes/schemas...

Am i question is wrong. do correct me if so.

Thanks,
Arun
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Deletion

 
0
  #5
Jun 6th, 2006
If your schema is a good one the "8th" row will be uniquely identified by it's primary key so to delete a single row in a table you would use syntax like:
  1. DELETE FROM <table> WHERE <primary KEY column> = <value>

You need to replace <table> with the table name obviously and <primary key column> with the column name and then <value> would be whatever the unique value is in primary key column of the 8th row of your table.

Example:
----------------------------------------
mytable |
----------------------------------------
pkID int | dbData varchar(50)|
----------------------------------------
1 |Hello |
2 |Goodbye |
.
.
.
8 |Go away |
----------------------------------------

so to delete the 8th row my TSQL would be:
  1. DELETE FROM mytable WHERE pkID = 8

Simple really.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Deletion

 
0
  #6
Jun 6th, 2006
the way you want to do it, I don't know of a way without knowing the criteria you are sorting by and the table schema.

if you have a primary key and are sorting by that primary key,
example table customer with primary key customerid,
you could do this
  1. DELETE FROM customer WHERE customerid = (SELECT top 1 c.customerid FROM (SELECT Top 8 customerid FROM customer ORDER BY customerid ASC) c ORDER BY c.customerid DESC)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC