I have 375 dialcodes in table "temp":
917277
917278
918083
...
9172738
I can do the following:
select * from cdr where
dnis like 917277% or
dnis like 917278% or
dnis like 918083% or
...
dnis like 9172738%
Is it possible to make a query including "select in" and "like %" conditions?
select * from cdr where dnis in (select dialcode% from temp)
You can use JOIN
and LIKE
to achieve similiar result:
SELECT c.* -- DISTINCT may be needed if dialcodes overlap each other
FROM cdr c
JOIN temp t
ON c.dnis LIKE t.dialcode || '%'
One method is to use exists
:
select c.*
from cdr c
where exists (select 1 from temp t where c.dnis like dialcode || '%' );
Note that this does not require distinct
, even when there might be multiple matches.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.