oracle - How to write a sql query for below condition -
i have 2 query selecting data same table
query1 :
select rownum rn , error_data_log ext_tab_log error_data_log like'error%' order rn, error_data_log ;
result :
+----+--------------------------+ | rn | error_data_log | +----+--------------------------+ | 1 | error processing column | +----+--------------------------+
query 2 :
select rownum rn , error_data_log ext_tab_log error_data_log 'kup-04101%' order rn, error_data_log ;
result :
+----+----------------------------------------------+ | rn | error_data_log | +----+----------------------------------------------+ | 1 | kup-04101: record 1 rejected in file abc.txt | | 2 | kup-04101: record 8 rejected in file abc.txt | | 3 | kup-04101: record 9 rejected in file abc.txt | +----+----------------------------------------------+
how can write sql query obtain below result:
+----+----------------------------------------------+ | rn | error_data_log | +----+----------------------------------------------+ | 1 | error processing column | | 2 | kup-04101: record 8 rejected in file abc.txt | +----+----------------------------------------------+
if understand correctly, can try this:
select rownum rn , error_data_log select rownum rn , error_data_log, 1 querynum ext_tab_log error_data_log like'error%' union select rownum rn , error_data_log, 2 querynum ext_tab_log error_data_log 'kup-04101%' group rn , error_data_log, querynum having rn > 1 , rn < max(rn) ) unionselect order querynum, rn, error_data_log ;
note: sql written directly here, didn't try myself.
Comments
Post a Comment