开发者

How to delete a particular row in a sql table? [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How to get the row number of ID of a sql table?

Say: i ne开发者_StackOverflow中文版ed to delete the 5th row, or the 6th or the 20th...???


I don't think this is possible in MySQL. The problem you have is the row number is subjective based on how the data is ordered. If you order your data by column 1 in ascending order and then you order by column 1 by descending order, which is row 1?

Preferably your tables should have primary key id fields in which you can specify them to delete.

DELETE FROM *table* WHERE id = *id*


You can use LIMIT in a DELETE request if you are using MySQL ^^

EDIT: Sorry it's not enough

The MySQL-specific LIMIT row_count option to DELETE tells the server the maximum number of rows to be deleted before control is returned to the client. This can be used to ensure that a given DELETE statement does not take too much time. You can simply repeat the DELETE statement until the number of affected rows is less than the LIMIT value.


$lcv = 0;
$row_to_delete = x;

$result = mysql_query("SELECT * FROM table");

while($row = mysql_fetch_array($result){
     if($lcv == $row_to_delete){
          mysql_query("DELETE");
     }

     $lcv++;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜