在关系数据库中,数据检索是最常用的关键操作。Oracle中使用select语句完成数据检索,在所有的sql语句中,select语句中最为强大和完善。
查询特定列是指检索表或视图某些列的数据,如果只需要取得部分列的信息,就需要查询特定列。当查询特定列时,因为需要指定列名,所以必须确定表或试图所包含的列。查询列的语法格式如下:
select [distinct column [expression[slias],…]] from table_name
其中指示查询数据库表的所有列
distinct知识消除结果集中的重复记录
column指定需要查询的表和列明,多列之间用逗号“,”分隔
alias指定列(表达式)的别名
table_name指定需要查询的表的名字
下述代码用于实现任务描述
查询部门表的部门编号,部门名称,和部门位置信息
select deptno,deptname,deptloc from dept;
当执行查询操作时,某些情况可能会返回相同的数据结果,因此在实际应用环境中,可能需要取消重复的数据,完成任务可以使用distinct关键字
本章及后续章节的sql命令都在sql developer的sql工作表或在sql * plus中调试通过。后面不再说明
从下面代码片段实现如下功能,分别通过不使用distinct和使用distinct两种情况,从emo表中查询所有部门编号
select deptno from emp;
select distinct deptno from emp;
执行结果分析
不使用distinct
select deptno from emp;
执行结果
deptno 20 30 30 20 30 30 10 20 10 30 20
使用distinct select distinct deptno from emp
执行结果10,20,30
可以看出使用distinct以后可以消除重复的行。
数据查询
最新推荐文章于 2022-07-29 10:38:35 发布