少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(22)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          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 閱讀(491) 評論(0)  編輯  收藏 所屬分類: oracle
          主站蜘蛛池模板: 逊克县| 仙居县| 上思县| 松江区| 洞头县| 定边县| 高安市| 宾阳县| 锦州市| 东平县| 崇阳县| 康定县| 眉山市| 黄平县| 建平县| 辽阳县| 航空| 工布江达县| 大邑县| 广丰县| 扬中市| 陕西省| 汕尾市| 星子县| 安龙县| 建昌县| 梅州市| 连南| 嵊泗县| 木里| 舒兰市| 招远市| 宣汉县| 葵青区| 萝北县| 宣城市| 武冈市| 祁东县| 团风县| 宁都县| 建宁县|