常用mysql笔记

系统 1296 0

1、insert into ... values

  insert into tables (col1,col2) values (1,2),(2,3);

2、insert into ... select

  insert into tables (col1,col2) select col3,col4 from table2;

3.insert into ... set

 insert into tables set col1=xx,col2=xx;

4.replace into  ...

 replace into  tables set col1=xx,col2=xx;  //先删除后插入,如果有自增id,慎用!(唯一索引下才可以用)

5. insert into ... on duplicate key   

 insert into tables set col1=xx,col2=xx on duplicate key update col1=xxx,col2=xxx;  //如果存在则更新,否则就是插入 (唯一索引下才可以用)

6.find_in_set(以逗号隔开,适用与in)

 select col1,col2 from tables where FIND_IN_SET(col1,'2,3,4')<1;  //col1的值在'2、3、4'里面则返回所在索引(从1开始)

7. group_concat

select group_concat(col1,',',col2) as colx from tables where id={$id} group by id;   //将col1,col2的值作为一个字段返回,按逗号分隔。  

8.if、ifnull

update tables set status=if(status='release','modifie',status) where id={$id};

9.create database if not exists database1;

10.create table if not exists table1 like table2;

 

常用mysql笔记


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论