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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:49:52+00:00 2026-06-15T16:49:52+00:00

I have 2 tables, items and members : CREATE TABLE IF NOT EXISTS `items`

  • 0

I have 2 tables, items and members :

CREATE TABLE IF NOT EXISTS `items` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`member` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `members` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

What if, for example I have a record inside items, such as

INSERT INTO  `test`.`items` (
`id` ,
`name` ,
`member`
)
VALUES (
NULL ,  'xxxx',  '1, 2, 3'
);

in members :

INSERT INTO `members` (`id`, `name`) VALUES
(1, 'asdf'),
(2, 'qwert'),
(3, 'uiop'),
(4, 'jkl;');

and I’d like to display items.member data with members.name, something like 1#asdf, 2#qwert, 3#uiop??

I’ve tried the following query,

SELECT items.id, items.name, GROUP_CONCAT(CONCAT_WS('#', members.id, members.name) ) as member

FROM `items` 
LEFT JOIN members AS members on (members.id = items.member)
WHERE items.id = 1

But the result is not like I expected. Is there any other way to display the data via one call query? Because I’m using PHP, right now, i’m explode items.member and loop it one by one, to display the members.name.

  • 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-15T16:49:54+00:00Added an answer on June 15, 2026 at 4:49 pm

    You could look into using FIND_IN_SET() in your join criteria:

    FROM items JOIN members ON FIND_IN_SET(members.id, items.member)
    

    However, note from the definition of FIND_IN_SET():

    A string list is a string composed of substrings separated by “,” characters.

    Therefore the items.member column should not contain any spaces (I suppose you could use FIND_IN_SET(members.id, REPLACE(items.member, ' ', '')) – but this is going to be extremely costly as your database grows).

    Really, you should normalise your schema:

    CREATE TABLE memberItems (
      item_id   INT(5) NOT NULL,
      member_id INT(5) NOT NULL,
      FOREIGN KEY   item_id REFERENCES   items (id),
      FOREIGN KEY member_id REFERENCES members (id)
    );
    
    INSERT INTO memberItems
      (item_id, member_id)
    SELECT items.id, members.id
    FROM   items
      JOIN members ON FIND_IN_SET(members.id, REPLACE(items.member,' ',''))
    ;
    
    ALTER TABLE items DROP member;
    

    This is both index-friendly (and therefore can be queried very efficiently) and has the database enforce referential integrity.
    Then you can do:

    FROM items JOIN memberItems ON memberItems.item_id = items.id
               JOIN members     ON members.id = memberItems.member_id
    

    Note also that it’s generally unwise to use GROUP_CONCAT() to combine separate records into a string in this fashion: your application should instead be prepared to loop over the resultset to fetch each member.

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

Sidebar

Related Questions

I have two tables: Table items: | id | name | description | |
I have two tables in a MySql DB: items id (char) name (varchar) description
I have five tables in my database. Members, items, comments, votes and countries. I
I have 2 tables: items and items_purchased . The tag name and other descriptive
I have three tables filters (id, name) items(item_id, name) items_filters(item_id, filter_id, value_id) values(id, filter_id,
I have 3 tables: items , purchases , and collaborators . A user can
I have three mysql tables items =========== id title items_in_categories ============================ id item_id category_id
I have 2 tables, one of them stores items and the other one stores
I have two tables, one called cart and one called items. Now I want
I'm kind of stumped. I have a table of items with fields: ID, title,

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.