Home  >  Article  >  Backend Development  >  php mysql where 怎么删除多个id?

php mysql where 怎么删除多个id?

WBOY
WBOYOriginal
2016-06-06 20:07:262199browse

如题
删除多条数据库的话 一般where id=1 or id=2 or id=3......
然而删除id是用一个数组装的 我的做法是遍历来删除
请问有没有简单点的方法 就是不遍历删除?
还有in 包含 、 not in 不包含、BETWEEN 在范围 、 not BETWEEN 不在范围
这四个是什么意思?

回复内容:

如题
删除多条数据库的话 一般where id=1 or id=2 or id=3......
然而删除id是用一个数组装的 我的做法是遍历来删除
请问有没有简单点的方法 就是不遍历删除?
还有in 包含 、 not in 不包含、BETWEEN 在范围 、 not BETWEEN 不在范围
这四个是什么意思?

in(1,2,3,4) ,就是这括号里边的全部符合
not in (5,6,7,8),就是括号里边的全部不符合
between 9 and 12 ,就是9-12(9,10,11,12)这个范围内全部符合
not between 12 and 15 ,就是12-15(12,13,14,15)这个范围内全部不符合

最简单的,自己写一遍看看结果就知道了。

你这个删除多条,既然是封装成数组,就转成逗号分隔的字符串放到 in 里就可以了

delete from 表 where id in(1,2,3) #id为1,2,3的
delete from 表 where id not in(1,2,3) #除1,2,3之外的所有记录

delete from 表 where id between 1 and 5 #id为1-3的
delete from 表 where id not between 1 and 5 #除1-5之外的所有记录

delete from table where id in (1,2,3))

把你的数组转成“1,2,3”字符串

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn