oracle - Find records with overlapping date range in SQL -


i have following table , data:

create table customer_wer(   id_customer number,   name varchar2(10),   surname varchar2(20),   date_from date,   date_to date not null,   constraint customer_wer_pk primary key (id_customer, data_from));  insert customer_wer values (4, 'karolina', 'komuda', '01-jan-00', '31-mar-00'); insert customer_wer values (4, 'karolina', 'komuda', '01-apr-00', '30-jun-00'); insert customer_wer values (4, 'karolina', 'komuda', '15-jun-00', '30-sep-00'); insert customer_wer values (4, 'karolina', 'komuda', '01-oct-00', '31-dec-00'); insert customer_wer values (4, 'karolina', 'komuda', '01-jan-01', '31-mar-01'); insert customer_wer values (4, 'karolina', 'komuda', '01-apr-01', '30-jun-01'); insert customer_wer values (4, 'karolina', 'komuda', '01-jul-01', '5-oct-01'); insert customer_wer values (4, 'karolina', 'komuda', '01-oct-01', '31-dec-01'); 

i need select query find records overlapping dates. means in example above, should have 4 records in result

number  2 3 7 8 

thank in advance. using oracle db.

try this:

select * t t1 join t t2 on (t1.datefrom > t2.datefrom , t1.datefrom < t2.dateto)           or (t1.dateto > t2.datefrom , t1.dateto < t2.dateto) 

thank example. after modification working:

select * customer_wer k join customer_wer w on k.id_customer = w.id_customer (k.date_from > w.date_to , k.date_from < w.date_to) or (k.date_to > w.date_from , k.date_to < w.date_to); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -