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

  • SEARCH
  • Home
  • 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 6218831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:40:37+00:00 2026-05-24T07:40:37+00:00

I have a database filled with some codes like EE789323 990 78000 These numbers

  • 0

I have a database filled with some codes like

EE789323
     990
   78000

These numbers are ALWAYS endings of a larger code. Now I have a function that needs to check if the larger code contains the subcode.

So if I have codes 90 and 990 and my full code is EX888990, it should match both of them.

However I need to do it in the following way:

SELECT * FROM tableWithRecordsWithSubcode
 WHERE subcode MATCHES [reg exp with full code];

Is a regular expression like this this even possible?

EDIT:

To clarify the issue I’m having, I’m not using SQL here. I just used that to give an example of the type of query I’m using.
In fact I’m using iOS with CoreData, and I need a predicate to fetch me only the records that match.
In the way that is mentioned below.

  • 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-05-24T07:40:38+00:00Added an answer on May 24, 2026 at 7:40 am

    Given the observations from a comment:

    Do you have two tables, one called tableWithRecordsWithSubcode and another that might be tableWithFullCodeColumn? So the matching condition is in part a join – you need to know which subcodes match any of the full codes in the second table? But you’re only interested in the information in the tableWithRecordsWithSubcode table, not in which rows it matches in the other table?

    and the laconic “you’re correct” response, then we have to rewrite the query somewhat.

    SELECT DISTINCT S.*
      FROM tableWithRecordsWithSubcode AS S
      JOIN tableWithFullCodeColumn     AS F
        ON F.Fullcode ...ends-with... S.Subcode
    

    or maybe using an EXISTS sub-query:

    SELECT S.*
      FROM tableWithRecordsWithSubcode AS S
     WHERE EXISTS(SELECT * FROM tableWithFullCodeColumn AS F
                   WHERE F.Fullcode ...ends-with... S.Subcode)
    

    This uses a correlated sub-query but avoids the DISTINCT operation; it may mean the optimizer can work more efficiently.

    That just leaves the magical ‘X …ends-with… T’ operator to be defined. One possible way to do that is with LENGTH and SUBSTR. However, SUBSTR does not behave the same way in all DBMS, so you may have to tinker with this (possibly adding a third argument, LENGTH(s.subcode)):

    LENGTH(f.fullcode) >= LENGTH(s.subcode) AND
    SUBSTR(f.fullcode, LENGTH(f.fullcode) - LENGTH(s.subcode)) = s.subcode
    

    This leads to two possible formulations:

    SELECT DISTINCT S.*
      FROM tableWithRecordsWithSubcode AS S
      JOIN tableWithFullCodeColumn     AS F
        ON LENGTH(F.Fullcode) >= LENGTH(S.Subcode)
       AND SUBSTR(F.Fullcode, LENGTH(F.Fullcode) - LENGTH(S.Subcode)) = S.Subcode;
    

    and

    SELECT S.*
      FROM tableWithRecordsWithSubcode AS S
     WHERE EXISTS(
           SELECT * FROM tableWithFullCodeColumn AS F
            WHERE LENGTH(F.Fullcode) >= LENGTH(S.Subcode)
              AND SUBSTR(F.Fullcode, LENGTH(F.Fullcode) - LENGTH(S.Subcode)) = S.Subcode);
    

    This is not going to be a fast operation; joins on computed results such as required by this query seldom are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SqlServer database that I've manually filled with some test data. Now
Good day, i have mongodb database filled with some data, i ensured that data
I have a mysql database filled up and running on a Windows computer, is
I have a database full of Asian-character filled records (Chinese, Japanese, and Korean) alongside
I have an SQLite database. I created the tables and filled them with a
I have a dropdown menu that is filled by a mysql database. I need
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
i have database table like this +-------+--------------+----------+ | id | ip | date |
Let's say I have a database filled with people with the following data elements:
I have a custom attribute that is being filled from a database. This attribute

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.