oracle union的用法

UNION 指令的目的是将两个 SQL 语句的结果合并起来,可以查看你要的查询结果.

select * from t_ar_ws_file where  is_delete='0' and status='80' and  id not in (

select archive_id from t_ps_archivemove_rel where owner_id in( select id from t_ps_archive_move where status='2' and table_id='4028a81a58f769140158f76b1c730042')

union

select  archive_id from t_ps_archivemove_rel where owner_id='402880e85967f468015969046d8301f5'

)

注意:union用法中,两个select语句的字段类型匹配,而且字段个数要相同,

UNION在进行表链接后会筛选掉重复的记录,所以在表链接后会对所产生的结果集进行排序运算,删除重复的记录再返回结果。也就是UNION有去重的效果


拓展:当将firstsql语句的查询结果作为secondsql语句的条件,并且firstsql语句返回的是一个list集合,可以用in函数,secondsql  where XX in(firstsql)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章