Your search intent is correct. The problem is that the wildcard %
only works the way you want to use it when using LIKE
. When you use it in your query:
SELECT calldate, src, dst
FROM cdr
WHERE src != '442%' AND src != '044%' LIMIT 50;
You are literally looking for those different than a 442%
and 044%
, therefore you will get results as 4420000
because 442%
is different from 4420000
. That is, the symbol %
is being considered literally.
What you need (as well @Carmen mentions) is to use a LIKE
. With LIKE
you can use %
to represent any number of characters so in this case use a LIKE '442%'
, for example, you would get all those that start with 442
: 442
, 442000
, 442001
, etc.
But you need the inverse, so what you have to do is use a NOT
in your query:
SELECT calldate, src, dst
FROM cdr
WHERE src NOT LIKE '442%' AND src NOT LIKE '044%' LIMIT 50;
What does it mean that you will get all those records in which src
does not start with 442
or 044
.