更新和条件-php快速入门系列教程

https://www.eruyi.cn/thread-1986-1-1.html

 

update
update开头,set后为设置的数据,不同的列使用','分开


举个栗子

update `table` set `field1`='value',`field2`='value2' where `id`=1;
where
where后面接的是条件,如果是update的话,后面接的意思就是修改那些行的内容,还有delete(删除),select(查询)的时候也会用到where语句


常用操作符
常用的有下面这些
=(相等),<>/!=(不等于),>(大于),<(小于),>=(大于等于),<=(小于等于)

like
模糊查询的时候会用到like

 

where `field` like '%模糊';/** 百分号在前表示搜索结尾为'模糊'的行 **/

/** 在后则表示搜索开头为'模糊'的行,两边都打上就是内容包括'模糊'的行 **/


in/not in
值是否是in中的其中一个,not in 相反


where `id` in (1,2,3);

where `id` not in (1,2,3);


多条件
多个条件就使用 and(且),or(或) 来连接,和我们写php中的&& || 一样


where `field`='value' and `field2`='value2';

where `field`='value' or (`field2`='value2' and `id` in (1,2,3));

 

相关推荐

网友评论(0)