Hi i have a proble in finding solution.
I have 3 tables:
- Customer
- customer_id
- customer_name
- Relation
- subscription_id
- customer_id
- 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.