mysql了基本语句_mysql基本语句

1.增

use myblog;

show tables;

insert into users(username, `password`, realname) values ('zhangsan', '123', '张三');

2.查

use myblogs;

show tables;

select * from users; --查询所有

select id,username form users; --查询id和username

select * from users where username='zhangsan'; --条件查询

select * from users where username='zhangsan' and `password`='123'; --并且

select * from users where username='zhangsan' or `password`='123'; --或者

select * from users where username like '%zhang%'; --模糊查询

select * from users where password like '%1%' order by id desc; --desc表示倒序,不加默认正序

select * form users where state <> '0'; -- <>表示不等于0

select count(id) as `count` from blogs; -- 查询总数

select * from blogs order by id desc limit 2; -- 查询第一页的两条数据

select * from blogs order by id desc limit 2 offset 2; -- 查询第二页的两条数据

3.改(更新)

如果遇到update users set realname...报错的话,先执行 SET SQL_SAFE_UPDATES = 0; 然后删掉再执行更新操作

update users set realname='李四2' where username='lisi';

4.删

delete from users where username='lisi';

-- 日常开发中我们通常是采用软删除

update users set state='0' where username='lisi';

5. 多表联查

select blogs.*, users.username, users.nickname

from blogs inner join users on users.id = blogs.userid

where users.username = 'lisi'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值