目录
普通查询
查询全部列数据
语法:
select * from 表名;
select - 表示查询哪些字段
from - 表示来自哪些表
* - 表示所有列
例:查询emp表中全部列数据 :
select *from emp;
查询指定列数据
语法:
select 列名1,列名2,……from 表名;
例:查询student表中,学员编号(sid),姓名(sname),性别(sex),分数(score)
select sid,sname,sex,score from student;
查询emp表中,编号(empno),姓名(ename),职位(job),工资(sal),入职时间(hiredate)
select empno,ename,job,sal,hiredate from emp;
为列指定别名
语法:
select 列名1 as 别名1,列名2 as 别名2,…… from 表名;
说明: as关键字可以省略。
例:查询dept表,部门编号(deptno),部门名称(dname),部门地址(loc),并起别名显示
select deptno as '部门编号',dname as '部门名称',loc as '部门地址' from dept;