数据库学习笔记1

今天学长给讲了讲数据库select语句,受益匪浅,为了防止时间侵蚀,记录一下微笑

select语句格式:

select .....

from .....

where .....

group by .....

having .....

order by..


(1)其中where中不可以使用别名,只可以使用字段名。

比如:

select id as uid,name as uname

form user_table

where uid=1        是错误的,此处只能使用字段名id而不能使用别名uid

(2)count(*)和count(字段名)的区别

当我们想查找一个表中符合条件记录的个数时会使用count()函数,count(*)和count(字段名)是有区别的,后者在字段名为NULL时会忽略此记录,而前者不会。也就是说当字段名不为NULL时,二者才没有区别。另外count(*)并非取出所有字段后再统计,不会影响到性能问题。

(3)连接的四种方式,内链接,左外连接,右外连接和全外连接

内链接:

两种写法,一种是 select from table1,table2,table3  where table1.id=table2.id and table2.name=table3.name        第二种是:select from table1 inner join table2 on table1.id=table2.id inner join table3 on table2.name=table3.name

	
左外连接:
             表A:                  表B:
                  id                     id
                  3                      3
                  8                      8
                  19                     24
 
左外连接后应为:
                 id id
                 3   3
                 8   8
                 19 NULL
        
语句为:select from A left join B on A.id=B.id 
右外连接:
       关键字 right join on 和左外连接正好相反
全外连接:      
              id   id
              3    3
              8    8
              19   NULL
              NULL 24
语句:select from A full outer join B on A.id=B.id
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值