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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:11:48+00:00 2026-06-14T19:11:48+00:00

I have two tables Table1 with list of users comma separated Name UserID abc

  • 0

I have two tables

Table1 with list of users comma separated

Name    UserID
abc     A,B,C,D
def     A,B,C

Table2

Name   UserID
abc    A
abc    B
abc    C
def    A
def    B

I need to find the users that are in table1 for each Name but not in table2 (There won’t ever be an instance when a UserID to Name pair is present in table2 but not in table1 as CSV).

The output should be

Name    UserID
abc     D
def     C

I can do this with PHP but is there a way this can be done through a query? I am not sure where to begin in case I’m doing this as a query. Can I parse in MySQL using comma as delimiter?

  • 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-06-14T19:11:49+00:00Added an answer on June 14, 2026 at 7:11 pm

    I plugged your test data into a test schema in SQLFiddle and ran the query that follows.

    Here’s the link to SQLFiddle with the test and positive results:
    http://sqlfiddle.com/#!2/83dfd/4/0

    Here’s the query:

    SELECT
    COALESCE(NORMALIZED_TABLE1.NAME, TABLE2.NAME) AS NAME,
    COALESCE(NORMALIZED_TABLE1.USERID, TABLE2.USERID) AS USERID
    FROM (
         SELECT NAME,
         SUBSTRING(
              USERID
              FROM CASE
                   WHEN INDEX_TABLE.POS = 1 THEN 1
                   ELSE INDEX_TABLE.POS + 1
                   END
              FOR CASE LOCATE(',', USERID, INDEX_TABLE.POS + 1)
                  WHEN 0 THEN CHARACTER_LENGTH(USERID) + 1
                  ELSE LOCATE(',', USERID, INDEX_TABLE.POS + 1)
                  END
                  - CASE
                    WHEN INDEX_TABLE.POS = 1 THEN 1
                    ELSE INDEX_TABLE.POS + 1
                    END
         ) AS USERID
         FROM TABLE1
         INNER JOIN (
              SELECT @rownum:=@rownum+1 POS
              FROM (
                 SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3
                 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6
                 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
              ) a, (
                 SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3
                 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6
                 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
              ) b, (
                 SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3
                 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6
                 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
              ) c, (SELECT @rownum:=0) r
         ) INDEX_TABLE
         ON INDEX_TABLE.POS <= CHAR_LENGTH(TABLE1.USERID)
         AND (
              INDEX_TABLE.POS = 1
              OR SUBSTRING(USERID FROM INDEX_TABLE.POS FOR 1) = ','
         )
    ) AS NORMALIZED_TABLE1
    LEFT OUTER JOIN TABLE2
    ON NORMALIZED_TABLE1.NAME = TABLE2.NAME
    AND NORMALIZED_TABLE1.USERID = TABLE2.USERID
    WHERE TABLE2.NAME IS NULL;
    

    If you have very long column width in table1 you might need to expand the “INDEX_TABLE” subquery. You can copy and paste over it with the code at this link to do so:
    http://www.experts-exchange.com/Database/MySQL/A_3573-A-MySQL-Tidbit-Quick-Numbers-Table-Generation.html

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

Sidebar

Related Questions

Need help figuring this out. I have two tables user ---- name skills (comma
I have two tables, name and address. I would like to list the last_name
I have two tables: Campaigns, Campaign_statistics. I need to output campaigns list with nested
I have two tables, for Users and Songs. I need to JOIN them both
I have two tables: Recipes RecipeId | UserId | Name | etc. and RecipeRatings
I have two tables, one containing a list of different options users can select
I have two tables. Questions: A list of questions, Results The users results to
I have two tables in MS Access. Table 1: users ID (auto int) Name
I have two tables: users table list of users stories list of stories -
I have two tables users with columns: uid, name, mail, etc users_roles with columns:

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.