Obtain all the information related to a customer












1















I wanted to obtain all the information related to an specific customer (given their account number)



I mean, i want to obtain name, lastname, email, billing/shipping addresses(including the ORIG_SYSTEM_REFERENCE for each one), city, region, country and so on.



I have tried different queries but no one really helped me.



SELECT
email,
a.entity_id AS addressId,
IF(def_billing_address.value = a.entity_id,1,0) AS isDefaultBillingAddress,
IF(def_shipping_address.value = a.entity_id,1,0) AS isDefaultSippingAddress,
addr_firstname.value AS firstname,
addr_lastname.value AS lastname,
addr_street.value AS street,
addr_city.value AS city,
addr_region_code.code AS stateCode,
addr_region.value AS state,
addr_zipcode.value AS postalCode,
addr_country.value AS countryCode,
addr_telephone.value AS telephone
FROM mg_customer_entity AS c
INNER JOIN mg_customer_address_entity AS a ON a.parent_id = c.entity_id

LEFT JOIN mg_customer_entity_int AS def_billing_address ON
(def_billing_address.entity_id = c.entity_id) AND
(def_billing_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_billing' and eav.entity_type_id = 1))
LEFT JOIN mg_customer_entity_int AS def_shipping_address ON
(def_shipping_address.entity_id = c.entity_id) AND
(def_shipping_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_shipping' and eav.entity_type_id = 1))
LEFT JOIN mg_customer_address_entity_varchar AS addr_zipcode ON
a.entity_id = addr_zipcode.entity_id AND
addr_zipcode.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'postcode' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_varchar AS addr_city ON
a.entity_id = addr_city.entity_id AND
addr_city.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'city' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_varchar AS addr_country ON
a.entity_id = addr_country.entity_id AND
addr_country.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'country_id' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_varchar AS addr_firstname ON
a.entity_id = addr_firstname.entity_id AND
addr_firstname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'firstname' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_varchar AS addr_lastname ON
a.entity_id = addr_lastname.entity_id AND
addr_lastname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'lastname' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_text AS addr_street ON
a.entity_id = addr_street.entity_id AND
addr_street.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'street' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_varchar AS addr_telephone ON
a.entity_id = addr_telephone.entity_id AND
addr_telephone.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'telephone' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_varchar AS addr_region ON
a.entity_id = addr_region.entity_id AND
addr_region.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region' and eav.entity_type_id = 2)
LEFT JOIN mg_customer_address_entity_int AS addr_region_id ON
a.entity_id = addr_region_id.entity_id AND
addr_region_id.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region_id' and eav.entity_type_id = 2)
LEFT JOIN mg_directory_country_region AS addr_region_code ON
addr_region_id.value = addr_region_code.region_id


This is the MAGENTO database diagram:



Can help me with this?



image










share|improve this question



























    1















    I wanted to obtain all the information related to an specific customer (given their account number)



    I mean, i want to obtain name, lastname, email, billing/shipping addresses(including the ORIG_SYSTEM_REFERENCE for each one), city, region, country and so on.



    I have tried different queries but no one really helped me.



    SELECT
    email,
    a.entity_id AS addressId,
    IF(def_billing_address.value = a.entity_id,1,0) AS isDefaultBillingAddress,
    IF(def_shipping_address.value = a.entity_id,1,0) AS isDefaultSippingAddress,
    addr_firstname.value AS firstname,
    addr_lastname.value AS lastname,
    addr_street.value AS street,
    addr_city.value AS city,
    addr_region_code.code AS stateCode,
    addr_region.value AS state,
    addr_zipcode.value AS postalCode,
    addr_country.value AS countryCode,
    addr_telephone.value AS telephone
    FROM mg_customer_entity AS c
    INNER JOIN mg_customer_address_entity AS a ON a.parent_id = c.entity_id

    LEFT JOIN mg_customer_entity_int AS def_billing_address ON
    (def_billing_address.entity_id = c.entity_id) AND
    (def_billing_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_billing' and eav.entity_type_id = 1))
    LEFT JOIN mg_customer_entity_int AS def_shipping_address ON
    (def_shipping_address.entity_id = c.entity_id) AND
    (def_shipping_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_shipping' and eav.entity_type_id = 1))
    LEFT JOIN mg_customer_address_entity_varchar AS addr_zipcode ON
    a.entity_id = addr_zipcode.entity_id AND
    addr_zipcode.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'postcode' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_varchar AS addr_city ON
    a.entity_id = addr_city.entity_id AND
    addr_city.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'city' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_varchar AS addr_country ON
    a.entity_id = addr_country.entity_id AND
    addr_country.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'country_id' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_varchar AS addr_firstname ON
    a.entity_id = addr_firstname.entity_id AND
    addr_firstname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'firstname' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_varchar AS addr_lastname ON
    a.entity_id = addr_lastname.entity_id AND
    addr_lastname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'lastname' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_text AS addr_street ON
    a.entity_id = addr_street.entity_id AND
    addr_street.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'street' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_varchar AS addr_telephone ON
    a.entity_id = addr_telephone.entity_id AND
    addr_telephone.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'telephone' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_varchar AS addr_region ON
    a.entity_id = addr_region.entity_id AND
    addr_region.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region' and eav.entity_type_id = 2)
    LEFT JOIN mg_customer_address_entity_int AS addr_region_id ON
    a.entity_id = addr_region_id.entity_id AND
    addr_region_id.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region_id' and eav.entity_type_id = 2)
    LEFT JOIN mg_directory_country_region AS addr_region_code ON
    addr_region_id.value = addr_region_code.region_id


    This is the MAGENTO database diagram:



    Can help me with this?



    image










    share|improve this question

























      1












      1








      1








      I wanted to obtain all the information related to an specific customer (given their account number)



      I mean, i want to obtain name, lastname, email, billing/shipping addresses(including the ORIG_SYSTEM_REFERENCE for each one), city, region, country and so on.



      I have tried different queries but no one really helped me.



      SELECT
      email,
      a.entity_id AS addressId,
      IF(def_billing_address.value = a.entity_id,1,0) AS isDefaultBillingAddress,
      IF(def_shipping_address.value = a.entity_id,1,0) AS isDefaultSippingAddress,
      addr_firstname.value AS firstname,
      addr_lastname.value AS lastname,
      addr_street.value AS street,
      addr_city.value AS city,
      addr_region_code.code AS stateCode,
      addr_region.value AS state,
      addr_zipcode.value AS postalCode,
      addr_country.value AS countryCode,
      addr_telephone.value AS telephone
      FROM mg_customer_entity AS c
      INNER JOIN mg_customer_address_entity AS a ON a.parent_id = c.entity_id

      LEFT JOIN mg_customer_entity_int AS def_billing_address ON
      (def_billing_address.entity_id = c.entity_id) AND
      (def_billing_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_billing' and eav.entity_type_id = 1))
      LEFT JOIN mg_customer_entity_int AS def_shipping_address ON
      (def_shipping_address.entity_id = c.entity_id) AND
      (def_shipping_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_shipping' and eav.entity_type_id = 1))
      LEFT JOIN mg_customer_address_entity_varchar AS addr_zipcode ON
      a.entity_id = addr_zipcode.entity_id AND
      addr_zipcode.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'postcode' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_city ON
      a.entity_id = addr_city.entity_id AND
      addr_city.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'city' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_country ON
      a.entity_id = addr_country.entity_id AND
      addr_country.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'country_id' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_firstname ON
      a.entity_id = addr_firstname.entity_id AND
      addr_firstname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'firstname' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_lastname ON
      a.entity_id = addr_lastname.entity_id AND
      addr_lastname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'lastname' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_text AS addr_street ON
      a.entity_id = addr_street.entity_id AND
      addr_street.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'street' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_telephone ON
      a.entity_id = addr_telephone.entity_id AND
      addr_telephone.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'telephone' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_region ON
      a.entity_id = addr_region.entity_id AND
      addr_region.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_int AS addr_region_id ON
      a.entity_id = addr_region_id.entity_id AND
      addr_region_id.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region_id' and eav.entity_type_id = 2)
      LEFT JOIN mg_directory_country_region AS addr_region_code ON
      addr_region_id.value = addr_region_code.region_id


      This is the MAGENTO database diagram:



      Can help me with this?



      image










      share|improve this question














      I wanted to obtain all the information related to an specific customer (given their account number)



      I mean, i want to obtain name, lastname, email, billing/shipping addresses(including the ORIG_SYSTEM_REFERENCE for each one), city, region, country and so on.



      I have tried different queries but no one really helped me.



      SELECT
      email,
      a.entity_id AS addressId,
      IF(def_billing_address.value = a.entity_id,1,0) AS isDefaultBillingAddress,
      IF(def_shipping_address.value = a.entity_id,1,0) AS isDefaultSippingAddress,
      addr_firstname.value AS firstname,
      addr_lastname.value AS lastname,
      addr_street.value AS street,
      addr_city.value AS city,
      addr_region_code.code AS stateCode,
      addr_region.value AS state,
      addr_zipcode.value AS postalCode,
      addr_country.value AS countryCode,
      addr_telephone.value AS telephone
      FROM mg_customer_entity AS c
      INNER JOIN mg_customer_address_entity AS a ON a.parent_id = c.entity_id

      LEFT JOIN mg_customer_entity_int AS def_billing_address ON
      (def_billing_address.entity_id = c.entity_id) AND
      (def_billing_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_billing' and eav.entity_type_id = 1))
      LEFT JOIN mg_customer_entity_int AS def_shipping_address ON
      (def_shipping_address.entity_id = c.entity_id) AND
      (def_shipping_address.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'default_shipping' and eav.entity_type_id = 1))
      LEFT JOIN mg_customer_address_entity_varchar AS addr_zipcode ON
      a.entity_id = addr_zipcode.entity_id AND
      addr_zipcode.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'postcode' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_city ON
      a.entity_id = addr_city.entity_id AND
      addr_city.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'city' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_country ON
      a.entity_id = addr_country.entity_id AND
      addr_country.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'country_id' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_firstname ON
      a.entity_id = addr_firstname.entity_id AND
      addr_firstname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'firstname' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_lastname ON
      a.entity_id = addr_lastname.entity_id AND
      addr_lastname.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'lastname' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_text AS addr_street ON
      a.entity_id = addr_street.entity_id AND
      addr_street.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'street' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_telephone ON
      a.entity_id = addr_telephone.entity_id AND
      addr_telephone.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'telephone' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_varchar AS addr_region ON
      a.entity_id = addr_region.entity_id AND
      addr_region.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region' and eav.entity_type_id = 2)
      LEFT JOIN mg_customer_address_entity_int AS addr_region_id ON
      a.entity_id = addr_region_id.entity_id AND
      addr_region_id.attribute_id = (SELECT attribute_id FROM mg_eav_attribute AS eav WHERE eav.attribute_code = 'region_id' and eav.entity_type_id = 2)
      LEFT JOIN mg_directory_country_region AS addr_region_code ON
      addr_region_id.value = addr_region_code.region_id


      This is the MAGENTO database diagram:



      Can help me with this?



      image







      magento-1.9






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      programming_amazingprogramming_amazing

      436




      436






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262138%2fobtain-all-the-information-related-to-a-customer%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262138%2fobtain-all-the-information-related-to-a-customer%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Polycentropodidae

          Magento 2 Error message: Invalid state change requested

          Paulmy