《拓文asp.net网站内容管理系统》官方演示站。
 设为首页  
 收藏本站
 作者:黄振安
 QQ:53854651
首 页 开源拓文.NET编程网站编程网页设计图形图像数据库软件工程留言本
    站内搜索:  
您现在的位置: 拓文网络 → 网站编程 → ASP → join 使用详解方式[正文]

热 门 文 章

相 关 文 章
  • ASP.NET性能优化
  • ASP脚本循环语句
  • 在.NET框架应用程序中发送电子邮件
  • .net打包自动安装数据库
  • asp.net开发wap必备:更好的匹配手机设备
  • 用ashx动态生成文件
  • windows 2003下asp.Net站点无法使用用户名+密码的方
  • ASP.NET中17种正则表达式
  • 提高ASP.Net应用程序性能的十大方法
  • 一个通过web.Mail发送邮件的类
  • join 使用详解方式
     
    [作者:不详    转贴自:不详    点击数:    更新时间:2006-3-14 9:15:50]

    join 方式
    (1) cross join
          参与select语句所有表的的所有行的笛卡尔乘积
          select au_lname ,title
          from authors cross join  titiles

         outer  join 对参与join的两个表有主从之分,处理方式以主表的每条数据去match 从属表的列,合乎条件的数据是我们所要的答案,不合乎条件的也是我们要的答案,只不过哪些从属表选取的列将被添上null。
    (2) left join
         左边的为主表,右边为从属表
         select a.cust_id ,b.order_date,b.tot_ant
         from customer a left join sales b
         on (a.cust_id =b.cust_id and b.order_date>''1996/10/15'')
         可以写为
         select a.cust_id,b.order_date,b.tot_ant
         from custom a
         left join (select * from sales where order_date>''1996/10/15'') b
        on a.cust_id =b.cust_id  
    (3) right join
         左边的表为从属表,右边的表为主表
    (4) self join
         self join 常用在同一表内不同数据间对同一列的比较
        select a.emp_no,a.emp_name,b.emp_no,b.emp_name,a.date_hired
        from employee a
        join employee b
        on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)
        order by a.date_hired
       这样会重复数据,只要加上一句 and a.emp_name>b.emp_name
    (5) full join
         不仅列出符合条件的数据,两边未符合join条件的数据也会一并列出。哪些未符合join条件的数据如果在select列中无法得到对应的值则填上null
        select a.cust_id,b.tot_amt
        from customer a full join sales b
        on a.cust_id=b.cust_id
    有表
     id   ic  name  amount
          I    *        *
          c
          i
          c
          i
          i  
       要求结果为 
        ic  name  amount  ic   name  amount
        i                         c
        i                         c
        i
        i
      select aaa.*,bbb.*
      from ( select (select count(id) from  aa as  b where (b.id<a.id) and (ic=''i'')) as     newid, * from aa a where ic=''i'') aaa
      full join
       (select (select count(id) from aa as b where b.id<a.id and ic=''c'') as newid,* from
     aa a where ic=''c'') bbb
    on aaa.newid=bbb.newid
    order by aaa.name
    6.使用 HASH 和 MERGE 联接提示
    此示例在 authors、titleauthors 和 titles 表之间建立三表联接,以生成一个作者及其著作的列表。查询优化器使用 MERGE 联接将 authors 和 titleauthors (A x TA) 联接在一起。然后,将 authors 和 titleauthors MERGE 联接 (A x TA) 的结果与 titles 表进行 HASH 联结以生成 (A x TA) x T。


    重要  指定联接提示后,要执行 INNER JOIN 时 INNER 关键字不再为可选,而必须显式说明。


    USE pubs
    SELECT SUBSTRING((RTRIM(a.au_fname) + '' '' + LTRIM(a.au_lname)), 1, 25)
       AS Name, SUBSTRING(t.title, 1, 20) AS Title
    FROM authors a INNER MERGE JOIN titleauthor ta
       ON a.au_id = ta.au_id INNER HASH JOIN titles t
       ON t.title_id = ta.title_id
    ORDER BY au_lname ASC, au_fname ASC

    下面是结果集:

    Warning: The join order has been enforced because a local join hint is used.
    Name                      Title               
    ------------------------- --------------------
    Abraham Bennet            The Busy Executive''s
    Reginald Blotchet-Halls   Fifty Years in Bucki
    Cheryl Carson             But Is It User Frien
    Michel DeFrance           The Gourmet Microwav
    Innes del Castillo        Silicon Valley Gastr
    ...                    ...
    Johnson White             Prolonged Data Depri
    Akiko Yokomoto            Sushi, Anyone?      

    (25 row(s) affected)


    首页 | 1 | 尾页  共 1 页
     
    hch004 打印本页 关闭窗口

         文 章 评 论
    评论人 查看该文章的评论 发表时间
       笔 名* : 0 50分 60分 70分 80分 90分 100分
    评论内容 *: (最多1000字。当前字数:0)


    没有相关评论,欢迎您参与!

    - 关于本站 - 网站帮助 - 下载声明 - 友情连接 - 网站地图 -
    Copyright © 2005-2006 myTopWin.Com. All Rights Reserved . [桂ICP备06004496号]