I have a pretty SQL select query that works as follows:
select * from session
where date(ts) = '2017-10-16'
and 7200 in (callingpartyno,finallycalledpartyno);
This retrieves 24 records as it should. The problem now is that I have 14 other extensions to check for within those same 2 columns and I don't know how to look for multiple values within multiple columns.
Let's say the previous query returns 24 and I do the same query with 7201 and it returns 6 rows. I want a way that would return 30 rows in that case. Same goes for 7200 through 7213, so to pull any row with that time stamp that has ANY of those 13 extensions in EITHER of those columns.
Is there a way to do this?
I tried like this:
select * from ambition.session
where date(ts) = '2017-10-16'
and 7276 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7314 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7295 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7306 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7357 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7200 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7218 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7247 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7331 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7255 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7330 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7000 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7215 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7240 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7358 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO)
and 7312 in (CALLINGPARTYNO, FINALLYCALLEDPARTYNO);
but I get no records at all
# in (x, y)could be true at any given time, and AND requires them to all be true.... AND (# in (x,y) OR #2 in (x,y) OR #3 in (x,y) OR ....)