MySql:如何从表中删除行除了具有特定ID的行
I have an html table with checkboxes. Users are permitted to delete rows from that html table except one specific one, whose value is hard coded in the DB.
If a user accidently checks it regardless, I want my server code (php) or even better the MySqL to run a delete query for all the rows they checked EXCEPT for that 1 specific row. So,something like this( which is wrong):
DELETE FROM table_name
WHERE row_id = some_value
EXCEPT row_id = some_value;
Many thanks !
我有一个带复选框的html表。 允许用户从该html表中删除行,除了一个特定的行,其值在数据库中是硬编码的。 p>
如果用户意外地检查它,我希望我的服务器代码(php)或更好的MySqL为他们检查的所有行运行删除查询,除了该特定行。 所以,像这样(这是错误的): p>
DELETE FROM table_name
WHERE row_id = some_value
EXCEPT row_id = some_value;
code> pre>
非常感谢! p>
div>
DELETE FROM table_name WHERE row_id NOT IN (do_not_delete_this_value );
do_not_delete_this_value will be the id of the row you don't want to delete, rest all records will get deleted.
I think the logic you want is AND
:
DELETE FROM table_name
WHERE row_id = some_value AND row_id <> some_value;
Of course, some_value
should be different most of the time.