简单的查询语句

1.查询全部的行和列,*代表所有的行和列

select * from 表名

2、查询部分行和列,部分行使用where来限制、部分列使用列名来限制

select * from 表名 where 行名='条件'   不是

select 列名1,列名2,列名3,列名3, from 表名

wehre  行名=‘条件’     是

“=”比较运算符,将左右两边的值进行相比,完全一致的会显示出来

同理

select * from 表名 where 行名<>'条件'   不是

select 列名1,列名2, from 表名 where 行名<>'条件'   不是

<> 比较运算符不等于    也可以使用“!=”

3.别名

(1)使用as关键字

select id as 编号,name as 名字,from  表名

(2)=赋值从左至右

select   编号=id,名字=name ,from  表名

(3)使用“空格”

select id 编号 ,name 名字,from  表名

4.查询为null值

seclet * from 表名 where 列名 is null

5.如果原来有数据,而后又被删除,那么使用is null 能否查询到

select * from   表名 where 列名 is null or 列名=‘’

--is null 与‘’区别  

--is null:从未录入过数据,没有地址

--' ':录入过数据,而后被删除,是有地址的

练习

use demo --使用数据库
go --开始
select * from text --查询所有的行和列

select * from text where name='小明' --只选择小明
select * from text where name<>'小明' --小明除外
select id 序号,name 名字, sex 性别 from text --加别名

猜你喜欢

转载自www.cnblogs.com/tangtangsimida/p/9471776.html