春兴精工股票

老鼠哥|网络站长门户网,PHP工程师,PHP教程,PHP100,PHP源码,PHP程序员
  • 老鼠哥网络站长门户改版新上线
  • 欢迎您老鼠哥网络门户网
  • 老鼠哥网络站长门户改版新上线
  • 欢迎您老鼠哥网络门户网

浅谈join 用法

出处:老鼠哥站长网 作者:老鼠哥 日期:2012-05-24 20:27 浏览:次
浅谈join用法,join分为如下几种:分为1.INNERJOIN2.LEFTJOINnbsp;nbsp;nbsp;3.RIGHTJOIN4.FULLOUTERJOIN首先设定一个我们要用的两个表nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp
join 分为如下几种:

分为1. INNER JOIN 2. LEFT JOIN   3. RIGHT JOIN 4.FULL OUTER JOIN

首先设定一个我们要用的两个表

                             表A                                                          表B

               ID                     NAME                                ID                 CLASS             

                 1                       IBM                                    1                    C1

                 2                     SONY                                 3                    C3

                 3                      BMW                                  4                     C4

1 INNER JOIN:          SELECT * FROM   A      INNER JOIN B ON A.ID=B.ID

得表                       ID                NAME          CLASS

                                1                   IBM                C1

                               3                 BMW               C3           

就是 两个表的ID都存在并相同 得到这两个表的组合表

2 LEFT JOIN :          SELECT * FROM   A      LEFT JOIN B ON A.ID=B.ID

得表                       ID                NAME          CLASS

                                1                   IBM                C1

                                2                   SONY             null

                               3                 BMW               C3           

   3   RIGHT JOIN :          SELECT * FROM   A      RIGHT JOIN B ON A.ID=B.ID

得表                       ID                NAME          CLASS

                                1                   IBM                C1

                                3                BMW               C3

                                4                 null                 C4           

对了RIGHT(右)   得到的是B(right语句的右边的表)的所有记录 而A表对应的记录没有的话也要补齐   (我也翻身了! 呵呵)

4 FULL OUTER JOIN:    SELECT * FROM   A      FULL OUTER JOIN B ON A.ID=B.ID

得表                       ID                NAME          CLASS

                                1                   IBM                C1

                               2                 SONY            null

                                3                BMW               C3

                                4                 null                 C4           

得到的是A和B的所有记录 而双方对应的记录没有的话也要补齐


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wangfou/archive/2009/12/20/5044868.aspx
顶一下
(0)
0%
踩一下
(0)
0%
最新评论
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片

春兴精工股票