1:检索单个列
select 列名 from 表名
2:检索多个列
select 列名1,列名2,列名3 from 表名
3:检索所有列
select * from 表名
4:检索不同的值
select distinct 列名 from 表名
5:限制结果
select top 5 列名 from 表名 //使用select top 5 语句,只检索前五行数据
6:排序数据
select 列名 from 表名 order by 列名 //在指定order by子句的时候,应该保证它是select语句中最后一条子句。如果不是最后一条子句,将会出错
7:按照多个列进行排序
select 列名1,列名2,列名3 from 表名 order by 列名2,列名3
8:按列的位置进行排序
select 列名1,列名2,列名3 from 表名 order by 2,3 //除了能用列名指出排序顺序后,order by 还支持按照相对列位置进行排序
9:指定排序方向
select 列名 from 表名 order by 列名 desc //desc降序排列,默认不输入的情况下是升序asc
10:使用where子句
select 列名1,列名2 from 表名 where 列名2=3.14 //这条语句是在这个表中检索两列,但是不返回所有的行,只返回列2值为3.14的行
11:where 子句操作符
= 等于 、<>不等于、!=不等于、< 小于、 <= 小于等于、 !<不小于、> 大于、 >=大于等于、 !>不大于、between 在指定的两个值之间、is null 为null值
11.1检查单个值
//第一个例子是列出所有价格(列名2)都小于10美元的产品。
select 列名1,列名2 from 表名 where 列名2 <10
11.2不匹配检查
//这个例子列出所有不是供应商DLL01(列名1)制造的产品
select 列名1,列名2 from 表名 where 列名1<>'DLL01'
11.3 范围检查
//检索价格(列名2)在5到10之间
select 列名1,列名2 from 表名 where 列名2 between 5 and 10
11.4空检查
select 列名1 from 表名 where 列名2 is null