简体   繁体   English

使用mysql从表中删除

[英]deleting from table using mysql

guys I have following table: 大家我有下表:

+--------------------------------------------------+
|id |  type    |   name   |    parent  |  group_id |
+--------------------------------------------------+
| 1 |  special |   name1  |    0       |  21       |
| 2 |  Group   |   name2  |    1       |  19       |
| 3 |  Group   |   name3  |    1       |  22       |
| 4 |  special |   name4  |    0       |  89       |
+--------------------------------------------------+

and right_id in table2 references on id in bo_right table2中的bo_rightright_id中的id bo_right

I want to delete rows where name = name2 and name3 . 我想删除name = name2name3 So how to do that? 那么该怎么做呢?

My own solution is: 我自己的解决方案是:

delete from bo_right WHERE name ='name2' AND name = 'name3';

but it doesn't work .. any solution .. thanks 但它不起作用..任何解决方案..谢谢

Change AND to OR : AND更改为OR

delete from bo_right WHERE name ='name2' OR name = 'name3';

Or you can use IN : 或者您可以使用IN

delete from bo_right WHERE name IN ('name2', 'name3');

You can simply change the AND in your query to an OR . 您可以简单地将查询中的AND更改为OR For a more elegant and compact readable way you could use: 为了更优雅,更紧凑的可读性,您可以使用:

DELETE from bo_right WHERE name in ('name2', 'name3');

to search for the appearence of the value from column name in a given set. 从给定集中的列name中搜索值的出现。

You have to use OR instead of AND like this: 您必须像这样使用OR而不是AND

delete from bo_right WHERE name ='name2' OR name = 'name3';

You want to delete the rows where the name is "name2" OR "name3" . 您要删除名称为"name2" "name3" It is not possible that the name is "name2" AND "name3" at the same time 名称不可能同时是"name2" "name3"

只需使用:

delete from bo_right WHERE  name in('name2','name3');

您可以使用in condition删除记录,如下所示:

delete from bo_right WHERE name in('name2', 'name3');

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM