Link to home
Start Free TrialLog in
Avatar of rivkamak
rivkamakFlag for United States of America

asked on

sql where not like from other table

I have 2 tables. I table with alot of data/columns and 1 table with 1 column exclusions.
i need a select statement that will show tableA where columnA is NOT LIKE '%tableB.text%"
AND tableA.columnB is NOT LIKE '%tableB.text%'

The closest I got to work is this which works as an exact match. How can I adjust this to show like with %% on both sides
select * from errorlogs
where errorlogs.filename not in
(select exclusion.text from exclusion)
and errorlogs.ip not in
(select exclusion.text from exclusion)

Open in new window

Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

There may be a better way to do this with a function and CROSS APPLY but...

Also I'm assuming you have a unique identifier of some kind in errorlogs which I am referring to as ErrorLogID

SELECT errorlogs.*
FROM errorlogs
SELECT DISTINCT errorlogs.ErrorLogID
FROM errorlogs
CROSS JOIN exclusion
WHERE errorlogs .filename LIKE '%' + exclusion.text + '%')
Avatar of rivkamak


That didn't work. I didn't get anything back
Please post your table creation scripts for errorlogs and exclusions so I can play with it.
FROM dbo.errorlogs el
INNER JOIN dbo.exclusion ex ON
    el.ColumnA NOT LIKE '%' + ex.text + '%' AND
    el.columnB NOT LIKE '%' + ex.text + '%'
I don't think that will work because you will actually get duplicate errorlog records for each exclusion entry that doesn't match.  As I understand it each errorlog record needs to be compared against eachexclusion entry and only included in the resultset if there is NO match found.
DOH, now that I see more of the q, you're probably right.  I went by only part of the original q.
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you