SQL之条件查询(检索数据)

1、检索单个列

1 select 
2 col_name 
3 from 
4 table_name;

2、检索多个列

1 select 
2 col_name, 
3 col_name2 
4 from 
5 table_name;

3、检索所有列

  使用·*通配符可以实现,但是一般而言,除非确实需要表中的每一列,否则最好别使用*通配符,尽管不用去明确列出所需的列,但检索不需要的列通常会降低检索速度和应用程序的性能

1 select
2 *
3 from 
4 table_name;

4、检索不同的值

  使用DISTINCT关键字

1 select
2 distinct
3 col_name
4 from
5 table_name;

5、限制结果

  限制数据结果条数,使用LIMIT关键字

1 select
2 col_name
3 from
4 table_name
5 limit
6 num

6、指定从某一行开始输出固定条数 

1 select
2 col_name
3 from
4 table_name
5 limit
6 num
7 offset
8 # 索引从0开始
9 num

 

posted on 2022-09-30 11:43  默玖  阅读(116)  评论(0编辑  收藏  举报

导航