Sample Header Ad - 728x90

Using a WHERE colname NOT LIKE (select * from otherTable)

0 votes
2 answers
177 views
So in essence what im trying to do is this: Given TBL1 (around 8,000 rows) | letters | | -------- | | abababa | | bcbcbcb | | cdcdcdc | and TBL2 (around 2,000 rows) | letters | | -------- | | ab | | bc | I want to write a query to find every row in TBL1 that does not contain atleast one of the substrings in TBL2 It has to be using a subquery because the actual code (cant post here bc its sensitive information) is a pretty complex query with a couple of concatenations and trims etc. Im trying to do this roughly
SELECT * FROM TBL1 WHERE TBL1.letters NOT LIKE '%'|| (SELECT letters FROM TBL2) ||'%'
My intention is to get the following output returned: | letters | | -------- | | cdcdcdc | As the last row does not contain 'ab' or 'bc'. to get an idea what my code looks like i will enclose with with out any identifying information.
SELECT
  *
FROM
  tbl1
WHERE
  tbl1.col1 NOT LIKE '%' ||(
    SELECT
      LTRIM(
        RTRIM(
          CONCAT(
            REPLACE(
              tbl2.col1,
              CONCAT(tbl2.col2, tbl2.col3),
              ""
            ),
            " ",
            tbl2.col2,
            " ",
            tbl2.col3
          )
        )
      )
    FROM
      tbl2
  ) || '%'
Asked by Shahzad Ansari (1 rep)
Feb 2, 2023, 10:03 PM
Last activity: Feb 5, 2023, 09:32 PM