記錄一下避免排序和刪除重複行

gaopengtttt發表於2012-09-27

select distinct  owner, table_name from test_sort2 order by owner,table_name;

建立一個所以再OWNER ,TABLE_NAME
這樣可以避免排序


select owner, table_name
  from test_sort2 a
 where A.ROWID = (select /*+ no_unnest */ max(rowid)
                    from test_sort2 b
                   where a.owner = b.owner
                     and a.table_name = b.table_name)
order by owner,table_name;

刪除重複的行
SQL> select * from oo;
 
                                     IT
---------------------------------------
                                      1
                                      1
                                      2
                                      2
 
SQL>
SQL> delete oo a where a.rowid <> (select  max(rowid)
  2                      from oo b
  3                     where a.it = b.it);
 
2 rows deleted
 
SQL> commit;
 
Commit complete
 
SQL> select * from oo;
 
                                     IT
---------------------------------------
                                      1
                                      2

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7728585/viewspace-745223/,如需轉載,請註明出處,否則將追究法律責任。

相關文章