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 1105255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:36:11+00:00 2026-05-17T01:36:11+00:00

I have a table A with this column: IDS(VARCHAR) 1|56|23 I need to run

  • 0

I have a table A with this column:

  IDS(VARCHAR)
  1|56|23

I need to run this query:

  select TEST from TEXTS where ID in ( select IDS from A where A.ID = xxx )

TEXTS.ID is an INTEGER. How can I split the string A.IDS into several ints for the join?

Must work on MySQL and Oracle. SQL99 preferred.

  • 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-17T01:36:12+00:00Added an answer on May 17, 2026 at 1:36 am

    First of all, you should not store data like this in a column. You should split that out into a separate table, then you would have a normal join, and not this problem.

    Having said that, what you have to do is the following:

    1. Convert the number to a string
    2. Pad it with the | (your separator) character, before it, and after it (I’ll tell you why below)
    3. Pad the text you’re looking in with the same separator, before and after
    4. Do a LIKE on it

    This will run slow!

    Here’s the SQL that does what you want (assuming all the operators and functions work in your SQL dialect, you don’t say what kind of database engine this is):

    SELECT
        TEXT   -- assuming this was misspelt?
    FROM
        TEXTS  -- and this as well?
        JOIN A ON
            '|' + A.IDS + '|' LIKE '%|' + CONVERT(TEXTS.ID) + '|%'
    

    The reason why you need to pad the two with the separator before and after is this: what if you’re looking for the number 5? You need to ensure it wouldn’t accidentally fit the 56 number, just because it contained the digit.

    Basically, we will do this:

    ... '|1|56|23|' LIKE '%|56|%'
    

    If there is ever only going to be 1 row in A, it might run faster if you do this (but I am not sure, you would need to measure it):

    SELECT
        TEXT   -- assuming this was misspelt?
    FROM
        TEXTS  -- and this as well?
    WHERE
        (SELECT '|' + IDS + '|' FROM A) LIKE '%|' + CONVERT(TEXTS.ID) + '|%'
    

    If there are many rows in your TEXTS table, it will be worth the effort to add code to generate the appropriate SQL by first retrieving the values from the A table, construct an appropriate SQL with IN and use that instead:

    SELECT
        TEXT   -- assuming this was misspelt?
    FROM
        TEXTS  -- and this as well?
    WHERE
        ID IN (1, 56, 23)
    

    This will run much faster since now it can use an index on this query.

    If you had A.ID as a column, and the values as separate rows, here’s how you would do the query:

    SELECT
        TEXT   -- assuming this was misspelt?
    FROM
        TEXTS  -- and this as well?
        INNER JOIN A ON TEXTS.ID = A.ID
    

    This will run slightly slower than the previous one, but in the previous one you have overhead in having to first retrieve A.IDS, build the query, and risk producing a new execution plan that has to be compiled.

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

Sidebar

Related Questions

I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
I have this XML in a column in my table: <keywords> <keyword name=First Name
I have a table with arbitrary columns and rows. This fact is irrelevant though
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have this table in an Oracle DB which has a primary key defined
I have a table like this: <table> <tfoot> <tr><td>footer</td></tr> </tfoot> <tbody> <tr><td>Body 1</td></tr> <tr><td>Body
I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100

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.