当前位置: 代码迷 >> 综合 >> sql条件查询语句
  详细解决方案

sql条件查询语句

热度:13   发布时间:2024-01-31 10:12:51.0

目录

1、去重查询distinct

2、使用and和or进行多条件查询

2.1、and

2.2、or

3、区分大小写查询binary

4、查询排序

4.1、升序asc(默认为升序)

4.2、降序desc

5、命令帮助help


1、去重查询distinct

distinct在表查询时去除表中重复的数据。

例如:select distinct name,age from studnts;去除name,age都相同的行。

2、使用and和or进行多条件查询

2.1、and

例如:查询表中id>3和age>25的记录

select id,name,age from students where id>3 and age>25;

2.2、or

例如:查询表中id>3或者age>25的记录

select id,name,age from students where id>3 or age>25;

3、区分大小写查询binary

mysql默认查询不区分大小写,使用binary可以区分大小写。

例如:select * from studnts where binary name='ZS';

name='zs'的记录将不会被查询出来。

4、查询排序

4.1、升序asc(默认为升序)

例如:select id from students order by id asc;

4.2、降序desc

例如:select id from studnets order by id desc;

5、命令帮助help

输入:

help show;

help select;

显示show和select的用法。

  相关解决方案