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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:38:23+00:00 2026-05-15T22:38:23+00:00

Hi i have a proble in finding solution. I have 3 tables: Customer customer_id

  • 0

Hi i have a proble in finding solution.

I have 3 tables:

  1. Customer
    • customer_id
    • customer_name
  2. Relation
    • subscription_id
    • customer_id
  3. Subscriptions

One customer can have relation with many subscriptions and i want to display data like so:

customer_id, customer_name, subscription_first, subscription_second, subscription_n 

…all in one line.

Can any one help me 😕

Ok, first of all, thanks for help 🙂

i did something like this and its working 🙂

SELECT `main_table`.*, `customer_lastname_table`.`value` AS `customer_lastname`, `customer_firstname_table`.`value` AS `customer_firstname`, IF(main_table.customer_id = 0, 1, 2) AS `type`, `store`.`group_id`, `store`.`website_id`, `subscription_table_one`.`subscription_code`, `subscription_table_two`.`subscription_code` FROM `newsletter_subscriber` AS `main_table`

 LEFT JOIN `customer_entity_varchar` AS `customer_lastname_table` ON customer_lastname_table.entity_id=main_table.customer_id
 AND customer_lastname_table.attribute_id = 7

 LEFT JOIN `customer_entity_varchar` AS `customer_firstname_table` ON customer_firstname_table.entity_id=main_table.customer_id
 AND customer_firstname_table.attribute_id = 5

 INNER JOIN `core_store` AS `store` ON store.store_id = main_table.store_id
 LEFT JOIN `b_newsletter_relations` AS `relation_table` ON relation_table.customer_id=main_table.customer_id
 LEFT JOIN `b_newsletter_subscriptions` AS `subscription_table_one` ON subscription_table_one.subscription_id=relation_table.subscription_id
 LEFT JOIN `b_newsletter_subscriptions` AS `subscription_table_two` ON subscription_table_one.subscription_id=relation_table.subscription_id
 GROUP BY `customer_id`

Aaa, and one more thing, it’s dynamic via PHP.

  • 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-15T22:38:24+00:00Added an answer on May 15, 2026 at 10:38 pm

    You can use the handy GROUP_CONCAT function available with MySQL. Below is the solution.

    create table customer (customer_id int, customer_name varchar(100));
    
    create table subscriptions (subscription_id int, subscription_name varchar(100));
    
    create table customer_relation (subscription_id int, customer_id int);
    
    insert into customer values (1,'cust1');
    insert into customer values (2,'cust2');
    
    insert into subscriptions values (1,'sub1');
    insert into subscriptions values (2,'sub2');
    insert into subscriptions values (3,'sub3');
    
    insert into customer_relation values (1,1);
    insert into customer_relation values (2,1);
    insert into customer_relation values (3,1);
    
    insert into customer_relation values (1,2);
    insert into customer_relation values (3,2);
    
    
    SELECT c.customer_id
         , c.customer_name
         , GROUP_CONCAT(s.subscription_name ORDER BY s.subscription_name) subs
      FROM customer c
         , subscriptions s
         , customer_relation x
     WHERE x.subscription_id = s.subscription_id
       AND x.customer_id = c.customer_id
    GROUP BY
           c.customer_id
         , c.customer_name;
    

    Results:

    customer_id    customer_name    subs
    1              cust1            sub1,sub2,sub3
    2              cust2            sub1,sub3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

simple problem, but perhaps no simple solution, at least I can't think of one
I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I am facing problem finding any solution for converting my PDF to HTMl/xml.This requirement
I am facing this problem and finding solution for this issue since last 2
I have a script that appends some rows to a table. One of the
I want to have generalised email templates. Currently I have multiple email templates with
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for

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.