Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9285665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:13:29+00:00 2026-06-18T19:13:29+00:00

I am using DB2 database. I have a query like: DELETE FROM MYSCHEMA.MY_TABLE WHERE

  • 0

I am using DB2 database.

I have a query like:

DELETE FROM MYSCHEMA.MY_TABLE WHERE (PROD LIKE 'AB%' OR PROD LIKE 'CD%' OR PROD LIKE 'EF%');

Above query is present in a properties file and I am executing it using a java program.

However, now I want to externalize the where condition.

I have created a new Table PROD_LIKE having a single column PROD_NAME with entries as below:

PROD_NAME
------------
AB
CD
EF
------------

I want to modify the delete query’s where condition such that it uses the entries present in above newly created table.

How can I achieve it ?

DB2 documentation says:

Resolving the problemEven though other databases like SQL Server or Oracle allow the use of database columns for both operands in a “like” comparison, DB2 is more restrictive. When the query database is a DB2 one has to avoid calculations or selects like the above mentioned. There is no way to use a database column as second operand when querying a DB2 and using “like” in a comparison.

What could be the alternative for this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:13:30+00:00Added an answer on June 18, 2026 at 7:13 pm

    In TSQL I’d probably do this,

    DELETE 
       T
    FROM 
        MYSCHEMA.MY_TABLE T 
        INNER JOIN PROD_NAME P
          ON LEFT(T.PROD,2) = P.PROD_NAME
    

    I’m sure the DB2 SQL is similar as I’m sure this is pretty much ANSI SQL.

    You could also try a more general to get rid of the hard coded 2

    DELETE 
       T
    FROM 
        MYSCHEMA.MY_TABLE T 
        INNER JOIN PROD_NAME P
          ON LEFT(T.PROD, LEN(P.PROD_NAM)) = P.PROD_NAME
    

    I don’t see why you need a like but yes you can if you want.

    DELETE 
       T
    FROM 
        MYSCHEMA.MY_TABLE T 
        INNER JOIN PROD_NAME P
          ON T.PROD LIKE P.PROD_NAME + '%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem using LIKE structure in DB2 : for example: select * from
I have a query, I have to sort the result from the DB2 database.
I have to fetch only 50 records at a time from database (DB2), for
I have a linq query from two database, however, each time the program stops
Can SQL Server or db2 do entire database exports like oracle (using exp command)?
Using Open JPA 2.0, and database is DB2 9.7. I would like to like
The database I'm accessing has two tables I need to query using DB2 SQL,
I have a python program that calls a stored procedure from db2 database. I
Im using a DB2 Database. What would be a suitable SQL query to find
I have a wrapper that I use to query a DB2 database. The way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.