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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:20:47+00:00 2026-05-16T15:20:47+00:00

I want to JOIN two table. Have no problem with that. I have problem

  • 0

I want to JOIN two table. Have no problem with that. I have problem with quite different thing.

Here’s my code:

SELECT * FROM `table1`
JOIN `table2` ON `table1.`field`=`table2`.`field`
...

The main issue is that table1.field is a string, comma-separated. Is there any good and fast way to split it?

Update
I found a function by Federico Cagnelutti

CREATE FUNCTION SPLIT_STR(
  x VARCHAR(255),
  delim VARCHAR(12),
  pos INT
)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
       LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
       delim, '');

Usage:

SELECT SPLIT_STR('a|bb|ccc|dd', '|', 3) as third;

Quite useful but it requires position integer as third parameter. Anyway, I do not know the amount of comma-separated words. Bascially, it’s up to 20 words, but I don’t know how many.

Update 2
To clarify my question. Here’s what I like to have (I know the following query is incorrect):

SELECT * FROM `table1`
JOIN `table2` ON `table2`.`id` IN (`table1`.`field`)

Update 3
Example strings: table1.field = ‘202, 185, 505’, table2.field = 202

  • 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-16T15:20:48+00:00Added an answer on May 16, 2026 at 3:20 pm

    I’m not sure I understand exactly what you need, but perhaps you could use the FIND_IN_SET function?

    SELECT * FROM `table1`
    JOIN `table2` ON FIND_IN_SET( `table2`.`field`, `table1.`field` ) > 0
    

    Performance might be a problem with this though.

    Update:

    If you have leading spaces in the data, as in the sample given, this could be handled with REPLACE. This wouldn’t work where there are embedded spaces, but would cater for cases where there are sometimes leading spaces and sometimes not. Example:

    SELECT  *
    FROM    table1 t1
    JOIN    table2 t2
    ON      FIND_IN_SET( t2.field, REPLACE( t1.field, ' ', '' ) ) > 0
    

    There is a limit of 64 members in a set, so if the comma-separated string is long this will break.

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

Sidebar

Related Questions

I have two tables that I want to join together. Table1 Year, ID, Theme,
I have two tables that I need to join... I want to join table1
I want to join two tables using JPQL : SELECT * FROM A LEFT
I am facing problem with Inner join in Access Database. I have two table
I want to join two tables together and have ONLY the data in Table
ok the problem is that I have to sum two sums from two tables
Similar question here but this is slightly different... I have two tables that I
I have two tables which I want to join together using a left outer
My situation is I have two tables. I want to join them together and
I have two tables, tbl_foo and tbl_bar , and I want to join these

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.