mysql查询语句最常用10个

如题所述

(1)查询表中全部信息:

select * from 表名

(2)查询表中指定列的信息:

select 列1,列2 from 表名

(3)去重:

select distinct 列... from 表名

(4)拼接结果:

select concat(列1,列2) from 表名

(5)设置别名(注意:关键字as可以省略)

select 列 as 别名 from 表名
select 列 别名 from 表名

(6)条件查询:

select 列... from 表名 where 条件

条件中比较运算符:(等于:=  大于:>  大于等于:>=  小于:<  小于等于:<=  不等于:!= 或 <>)

(7)where 列  比较运算符  值

注意:字符串、日期需使用单引号括起来

(8)逻辑运算符(并且:and或&&   或:or   非:not或!)

where 条件1 逻辑运算符 条件2
where not 条件

(9)范围查询:

where 列 between 条件1  and 条件2;          //列在这个区间的值where 列 not between 条件1 and 条件2;    //不在这个区间where !( 列 between 条件1 and 条件2 );     //同样表示不在这个区间

集合查询(判断列的值是否在指定的集合中):

where 列 in(值1,值2);          //列中的数据是in后的值里面的where 列 not in(值1,值2);   //不是in中指定值的数据

null值查询(注意:列中值为null不能使用=去查询):

where 列 is null;  //查询列中值为null的数据


资料来源 网页链接

温馨提示:答案为网友推荐,仅供参考