简体   繁体   English

如何删除mysql数据库表中的所有行,其中某一列的值= 0?

[英]How can I delete all rows within a table in a mysql database, which value = 0 for one of the columns?

So basically, it's like this: 所以基本上,是这样的:

The table is called phpbb_posts 该表称为phpbb_posts

The column name is post_approved 列名是post_approved

I want to run a query which deletes all rows in phpbb_posts table in which the post_approved value is 0 (All rows contain either a 1 or a 0 value for the column post_approved ) 我想运行它删除在所有行的查询phpbb_posts表,其中post_approved值为0(所有的行包含一个1或该列的0值post_approved

I wanted to make sure I am running the correct query, before running it. 我想确保在运行正确的查询之前,先运行它。

DELETE FROM phpbb_posts
WHERE EXISTS(
              SELECT * 
              FROM phpbb_posts
              WHERE (post_approved = 0) 
            )

Please tell me if this code is correct; 请告诉我该代码是否正确; or if it is wrong, please tell me the correct code. 否则,请告诉我正确的代码。



CODE FIXED (thanks!): 固定代码(谢谢!):

DELETE FROM phpbb_posts WHERE post_approved = 0

RESULT: 结果:

35743 rows deleted. ( Query took 1.3562 sec )

PS FOR THOSE WONDERING, THIS REMOVES ALL SPAM POSTS FROM PHPBB IN ONE FELL SWOOP! PS真是太神奇了,它一次删除了PHPBB的所有垃圾邮件! (assuming you don't have any valid posts you want to approve). (假设您没有要批准的任何有效信息)。 Instead of going through moderator and "disapproving" for 50,000 pages, you can do this! 您可以执行此操作,而不必经过主持人并“拒登” 50,000个页面。 :) :) and yes I checked in the moderator queue and all the spam posts i never approved are gone! :) :)是的,我检查了主持人队列,我从未批准的所有垃圾邮件都消失了! YAY! 好极了!

做就是了

    DELETE FROM phpbb_posts WHERE post_approved = 0

Just use 只需使用

DELETE FROM phpbb_posts
WHERE post_approved = 0

that should do it fine. 那应该做得很好。

I would think just: 我会认为:

DELETE FROM phpbb_posts
WHERE post_approved = 0;

Would suffice 足够了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除MySQL中数据库的所有表中的所有行? - How to delete all rows in all table of a database in MySQL? 如何找到所有数据库表中共有的值? - How can I find a value which is common in all the database table? 我如何在mysql中删除重复的行并保留已填充其他一些字段的行? - How can i delete duplicates rows in mysql retaining the one which is having some other fields filled? 如何通过检查另一列重复值来更改mysql表以添加包含所有行通用值的列 - how to alter a mysql table to add a column which contains a common value for all rows by checking another columns repeating value 如何删除具有递归结构(MySQL)的表的所有行? - How do I delete all the rows of a table with a recursive structure (MySQL)? 如何使用MySQL删除一列中重复的所有行? - How can I delete all rows with duplicates in one column using MySQL? 如何更新一列值以包含 MySQL 中表的两列中的所有值? - How do I update one column value to contain all of the value in two columns of a table in MySQL? 如何使用一条 SQL 语句删除 MySQL 数据库中的所有触发器? - How can I delete all the triggers in a MySQL database using one SQL statement? 在mysql中,我如何只从一个表中获取行,而该行不链接到具有特定ID的另一表中的任何行 - In mysql how can I get only rows from one table which do not link to any rows in another table with a specific ID 如何一键删除数据库中的所有行 - How to delete all rows in database on one click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM