Note that there are some explanatory texts on larger screens.

plurals
  1. POComplex SQL query :: display data inline from multiply tables
    primarykey
    data
    text
    <p>Hi i have a proble in finding solution.</p> <p>I have 3 tables:</p> <ol> <li>Customer <ul> <li>customer_id</li> <li>customer_name</li> </ul></li> <li>Relation <ul> <li>subscription_id</li> <li>customer_id</li> </ul></li> <li>Subscriptions</li> </ol> <p>One customer can have relation with many subscriptions and i want to display data like so:</p> <pre><code>customer_id, customer_name, subscription_first, subscription_second, subscription_n </code></pre> <p>...all in one line.</p> <p>Can any one help me :?</p> <p>Ok, first of all, thanks for help :)</p> <p>i did something like this and its working :)</p> <pre><code>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` </code></pre> <p>Aaa, and one more thing, it's dynamic via PHP.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload