One column contained in another

One column contained in another

I have a table in which I need to compare two columns. Column A contains a string that should be part of Column B. For example, Column A is "Boxer" and Column B is "Dog Breed Boxer". I need to find the rows where the string in Column A is not embedded as part of the string in Column B.

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

Seems pretty straightforward. Try this:

select A, B
  from yourtable
 where B not like '%' || A || '%'

Note: you may have to substitute your particular database's string concatenation operator for the standard SQL "double pipes" (||) operator.

For More Information


This was first published in December 2003

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.