oracle 随笔

1.oracle 在 进行一对多关联查询时,只显示其中一的列表 (下面是代码部分);

-----------------------------------

order(1):

id order_no price ...

------------------------------------

orderItem(n):

id order_id ...

------------------------------------

(ps:n代表多)

select * from order a where exists(select id from orderItem b where b.order_id = a.id);

简单明了,相必大家都看明白了吧。

exists相当于一个子查询。里面返回的是boolean值

 通常exists适用于外表小,内表大的情况,而in适用于外表大内表小的情况,exists比in的效率要高一些,因为in不走索引。

2.查询出重复的数据

select * from tem_search_log a where ID not in(select min(id) from tem_search_log group by log_date,user_name) and user_name not in ('admin','test1','test2');

3.删除用户的所有表的数据

SELECT 'DELETE FROM '|| table_name || ';' FROM USER_TABLES

 

posted @ 2014-06-05 16:15  mr.g.  阅读(160)  评论(0编辑  收藏  举报