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)

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