devxlogo

Pattern Matching

Pattern Matching

Question:
How can I use SQL to specify a query like the example below:

    select * from mytable where column like ‘a[bc]’
This should match both “ab” and “ac” but not “ad.”

Answer:
SQL does not have strong pattern matching facilities. For the example you’ve provided, you’ll have to construct the query using the IN predicate:

    SELECT * FROM MyTable         WHERE col IN (ab, ac);
If your list is extensive, you might want to use a subquery:
    SELECT * FROM MyTable         WHERE col IN             (SELECT value FROM ValueTable);

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist