select * from tableName;
select field as nickName from tableName;
-- 函数 concat()
select concat(field,'string') as nickNmae from tableName;
-- 去重 distinct
select distinct field from tableName;
-- 查询版本
select version();
-- 查询自增的步长 (变量)
select @@auto_increment_increment;
-- 字段处理
select field + 100 as nickName from tableName;
-- 模糊查询
select field from tableName where field like 's__';
- 单个字符 % 任意字符
逻辑运算符
运算符
语法
描述
AND &&
a && b a and b
与
OR ||
a || b a or b
或
NOT !
! a not a
非
比较运算符(均返回布尔值)
运算符
语法
描述
IS NULL
a is null
为空
IS NOT NULL
a is not null
非空
BETWEEN
a between 1 and 2
1,2之间 也包括1 2
LIKE
a like ‘%s’
_单个字符 % 任意字符
IN
a in (1,2,3)
满足其中之一
联表查询
连接方式
注意
inner join on
显示两个表都存在的字段
left join on
显示左表所有字段
right join on
显示右表所有字段
自连接
将一张表看成2张一样的表
升序 降序
-- 升序
order by field asc;
-- 降序
order by field desc;
DQL查询数据DQL(Data Query Language)select * from tableName;select field as nickName from tableName;-- 函数 concat()select concat(field,'string') as nickNmae from tableName;-- 去重 distinctselect distinct field from tableName;-- 查询版本select version();--