欢迎光临
我们一直在努力

sql note-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

select *
from usertable
order by age desc,userid asc  先按年龄从大到小排序,相同的年龄的再按uerid从小到大排序。
=========================================================================================
select p1.pub_id,p2.pub_id,p1.pr_info
from pub_info as p1 inner join pub_info as p2
on datalength(p1.pr_info)=datalength(p2.pr_info)
=========================================================
连接类型,可分为三种:内连接、外连接和交叉连接.内连接又分为等值连接、自然连接和不等连接三种.外连接分为左外连接(left outer join或left join)、右外连接(right outer join或right join)和全外连接(full outer join或full join)三种.

下面使用等值连接列出authors和publishers表中位于同一城市的作者和出版社:
select *
from authors as a inner join publishers as p
on a.city=p.city
又如使用自然连接,在选择列表中删除authors 和publishers 表中重复列(city和state):
select a.*,p.pub_id,p.pub_name,p.country
from authors as a inner join publishers as p
on a.city=p.city

交叉连接不带where 子句,它返回被连接的两个表所有数据行的笛卡尔积,返回到结果集合中的数
据行数等于第一个表中符合查询条件的数据行数乘以第二个表中符合查询条件的数据行数。
例,titles表中有6类图书,而publishers表中有8家出版社,则下列交叉连接检索到的记录数将等
于6*8=48行。
select type,pub_name
from titles cross join publishers
order by type

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » sql note-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章