初级SQL

1.oracle 用start with --connect by

    select column
    from table_name
          start with  column = value
         connect by prior 父主键 = 子主键。

2.连接

    a表          b表
     id          id
     1            1
     2            2
     3            4


左: select * from a left join b on a.id = b.id;

oralce  :
      select * from a,b where a.id = b.id(+);

      id   id
      1     1
      2     2
      3

右: select * from a right join  b on a.id = b.id;

  oracle:
      select * from a,b where a.id(+) = b.id;

      id   id
       1    1
       2    2
            4

内: select * from a join b on a.id = b.id;

   oracle:
       select * from a,b where a.id = b.id;

      id   id
       1    1
       2    2


全外:select * from a full join b on a.id = b.id;

   oracle:
     select * from a,b where a.id = b.id(+)
     union
     select * from a,b where a.id(+) = b.id ;

     id    id
      1     1
      2     2
      3     
            4

完全: 交叉连接 或笛卡尔积

  select * from a,b;

  select * from a cross join b;

   id     id
   1      1
   1      2
   1      4
   2      1
   2      2
   2      4
   3      1
   3      2
   3      4

左外连接:

  select *  from a,b  where a.id = b.id(+) and b.id = 2;

  id    id
  2      2

where 后第二个加号,作用修改右边表记录的显示,例如: 如果 b.id(+) = 2
显示为2,否则显示null


select * from a,b where a.id = b.id(+)  and b.id(+) = 2

   id     id
   2       2
   3
   1

猜你喜欢

转载自maiting.iteye.com/blog/1699581