Knot
Knot

Reputation: 141

Use IN operator along with NOT LIKE considering wild card matching

I am having two tables.

TableA(% is a wild card character)

---------------
str           |
---------------
abc%          |
xyz%          |
pop%          |
---------------

TableB
--------------------
id | name | domain |
--------------------
1  | Paul | zzz.ko |
2  | John | abc.lo |
3  | Kal  | pop.cm |
--------------------

I want to fetch all the records from TableB where domain does not match with TableA str field( wild card matching).

Upvotes: 2

Views: 39

Answers (1)

access_granted
access_granted

Reputation: 1907

A crude query would look like this:

select * from TableB b
where not exists (select 1 from TableA a where b.domain like a.str)

Also, you might want to avoid using "str" as a column name.

Upvotes: 2

Related Questions