少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
          create table abin6(id integer,
          name nvarchar2(100),
          score integer,
          constraint pk_abin6 primary key(id));

          create table abin7(id integer,
          address nvarchar2(100),
          sid integer,
          constraint pk_abin7 primary key(id),
          constraint fk_abin7 foreign key (sid) references abin6(id)
          );



          select * from abin6 t left join abin7 s on t.id=s.sid and t.id=1;
          select * from abin6 t left join abin7 s on t.id=s.sid where t.id=1;
          select * from abin6 t,abin7 s where t.id=s.sid(+) ;
          select * from abin6 t,abin7 s where t.id(+)=s.sid;
          select * from abin6 t,abin7 s where s.sid(+)=t.id;
          select * from abin6 t,abin7 s where s.sid=t.id(+);
          select * from abin6 t inner join abin7 s on t.id=s.sid;
          select * from abin6 t union select * from abin7 s where exists (select * from abin6 k where s.sid=k.id and k.id
          =1);
          select * from abin6 t full join abin7 s on t.id=s.sid;
          select * from abin7 s full join abin6 t on s.sid=t.id;
          select * from abin6 natural join abin7;
          select * from abin6 t cross join abin7;

          以下兩句是等價查詢:
          select * from abin6 t where id=1 or id=2;
          select * from abin6 t where t.id=1 union all select * from abin6 s where s.id=2;


          一。查找重復記錄
          1。查找全部重復記錄
          select * from abin4 s where s.name in (select t.name from abin4 t
          group by t.name having count(t.name)>1);
          select * from abin4 s where exists (select * from abin4 t where t.name=s.name
          group by t.name  having count(t.name)>1 );

          2。過濾重復記錄(只顯示一條)
          select * from abin4 s where s.id in (select max(id) from abin4 t group by t.name );
          二。刪除重復記錄
          1。刪除全部重復記錄(慎用)
          Delete 表 Where 重復字段 In (Select 重復字段 From 表 Group By 重復字段 Having Count(*)>1)
          2。保留一條(這個應該是大多數人所需要的 ^_^)
          Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)
          注:此處保留ID最大一條記錄




          http://blog.csdn.net/csskysea/article/details/6987760
          posted on 2012-12-05 00:33 abin 閱讀(486) 評論(0)  編輯  收藏 所屬分類: oracle
          主站蜘蛛池模板: 金坛市| 秀山| 康马县| 三亚市| 大庆市| 二连浩特市| 策勒县| 蒲城县| 泾源县| 丰镇市| 滕州市| 荆门市| 昌乐县| 开江县| 烟台市| 栾城县| 哈密市| 大足县| 乐陵市| 东辽县| 喀喇沁旗| 宜兰县| 梁平县| 华安县| 临夏市| 普陀区| 嘉黎县| 河曲县| 宁陵县| 霍城县| 正蓝旗| 桓台县| 冷水江市| 滦南县| 镇赉县| 盐城市| 临沂市| 新建县| 鄱阳县| 宁海县| 砀山县|