Modifying a query (get products using SQL only)












0















I am trying without success to obtain all products from MAGENTO database. (SQL only)



After a few attempts i got this query (it is not working properly because it shows empty rows after executing it):



SELECT 
main.entity_id,
main.sku,
code_brand.value AS code_brand,
code_business_unit.value AS code_business_unit,
code_line.value AS code_line,
code_group.value AS code_group,
code_business.value AS code_business

FROM catalog_product_entity AS main

LEFT JOIN catalog_product_entity_int AS code_brand
ON main.entity_id = code_brand.entity_id

LEFT JOIN catalog_product_entity_varchar AS code_business_unit
ON main.entity_id = code_business_unit.entity_id

LEFT JOIN catalog_product_entity_varchar AS code_line
ON main.entity_id = code_line.entity_id

LEFT JOIN catalog_product_entity_int AS code_group
ON main.entity_id = code_group.entity_id

LEFT JOIN catalog_product_entity_int AS code_business
ON main.entity_id = code_business.entity_id


WHERE code_brand.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code LIKE "code_brand"
AND 'entity_type_id' = (
SELECT entity_type_id
FROM eav_entity_type
WHERE entity_type_code = 'catalog_product'
)
)

AND code_business_unit.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code LIKE "code_business_unit"
AND 'entity_type_id' = (
SELECT entity_type_id
FROM eav_entity_type
WHERE entity_type_code = 'catalog_product'
)
)

AND code_line.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code LIKE "code_line"
AND 'entity_type_id' = (
SELECT entity_type_id
FROM eav_entity_type
WHERE entity_type_code = 'catalog_product'
)
)


AND code_group.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code LIKE "code_group"
AND 'entity_type_id' = (
SELECT entity_type_id
FROM eav_entity_type
WHERE entity_type_code = 'catalog_product'
)
)


AND code_business.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code LIKE "code_business"
AND 'entity_type_id' = (
SELECT entity_type_id
FROM eav_entity_type
WHERE entity_type_code = 'catalog_product'
)
)


This is what i need: i want to obtain ALL products that have these attributes:



image



A guy suggested me to use this query:



    SELECT 
`e`.`sku`,
IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

FROM
`catalog_product_entity` AS `e`
INNER JOIN
`catalog_product_entity_varchar` AS `at_name_default`
ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND
(`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
`at_name_default`.`store_id` = 0
LEFT JOIN
`catalog_product_entity_varchar` AS `at_name`
ON (`at_name`.`entity_id` = `e`.`entity_id`) AND
(`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
(`at_name`.`store_id` = 1)
INNER JOIN
`catalog_product_entity_text` AS `at_description_default`
ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND
(`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
`at_description_default`.`store_id` = 0
LEFT JOIN
`catalog_product_entity_text` AS `at_description`
ON (`at_description`.`entity_id` = `e`.`entity_id`) AND
(`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
(`at_description`.`store_id` = 1)


The problem is that i dont fully understand how does this work.. he talked about store view for an specific id and i dont know how to do that.



PS: i am using MAGENTO 1.9



This is the database diagram:



Image2









share







New contributor




programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I am trying without success to obtain all products from MAGENTO database. (SQL only)



    After a few attempts i got this query (it is not working properly because it shows empty rows after executing it):



    SELECT 
    main.entity_id,
    main.sku,
    code_brand.value AS code_brand,
    code_business_unit.value AS code_business_unit,
    code_line.value AS code_line,
    code_group.value AS code_group,
    code_business.value AS code_business

    FROM catalog_product_entity AS main

    LEFT JOIN catalog_product_entity_int AS code_brand
    ON main.entity_id = code_brand.entity_id

    LEFT JOIN catalog_product_entity_varchar AS code_business_unit
    ON main.entity_id = code_business_unit.entity_id

    LEFT JOIN catalog_product_entity_varchar AS code_line
    ON main.entity_id = code_line.entity_id

    LEFT JOIN catalog_product_entity_int AS code_group
    ON main.entity_id = code_group.entity_id

    LEFT JOIN catalog_product_entity_int AS code_business
    ON main.entity_id = code_business.entity_id


    WHERE code_brand.attribute_id = (
    SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code LIKE "code_brand"
    AND 'entity_type_id' = (
    SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'
    )
    )

    AND code_business_unit.attribute_id = (
    SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code LIKE "code_business_unit"
    AND 'entity_type_id' = (
    SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'
    )
    )

    AND code_line.attribute_id = (
    SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code LIKE "code_line"
    AND 'entity_type_id' = (
    SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'
    )
    )


    AND code_group.attribute_id = (
    SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code LIKE "code_group"
    AND 'entity_type_id' = (
    SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'
    )
    )


    AND code_business.attribute_id = (
    SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code LIKE "code_business"
    AND 'entity_type_id' = (
    SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'
    )
    )


    This is what i need: i want to obtain ALL products that have these attributes:



    image



    A guy suggested me to use this query:



        SELECT 
    `e`.`sku`,
    IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
    IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

    FROM
    `catalog_product_entity` AS `e`
    INNER JOIN
    `catalog_product_entity_varchar` AS `at_name_default`
    ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND
    (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
    `at_name_default`.`store_id` = 0
    LEFT JOIN
    `catalog_product_entity_varchar` AS `at_name`
    ON (`at_name`.`entity_id` = `e`.`entity_id`) AND
    (`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
    (`at_name`.`store_id` = 1)
    INNER JOIN
    `catalog_product_entity_text` AS `at_description_default`
    ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND
    (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
    `at_description_default`.`store_id` = 0
    LEFT JOIN
    `catalog_product_entity_text` AS `at_description`
    ON (`at_description`.`entity_id` = `e`.`entity_id`) AND
    (`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
    (`at_description`.`store_id` = 1)


    The problem is that i dont fully understand how does this work.. he talked about store view for an specific id and i dont know how to do that.



    PS: i am using MAGENTO 1.9



    This is the database diagram:



    Image2









    share







    New contributor




    programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I am trying without success to obtain all products from MAGENTO database. (SQL only)



      After a few attempts i got this query (it is not working properly because it shows empty rows after executing it):



      SELECT 
      main.entity_id,
      main.sku,
      code_brand.value AS code_brand,
      code_business_unit.value AS code_business_unit,
      code_line.value AS code_line,
      code_group.value AS code_group,
      code_business.value AS code_business

      FROM catalog_product_entity AS main

      LEFT JOIN catalog_product_entity_int AS code_brand
      ON main.entity_id = code_brand.entity_id

      LEFT JOIN catalog_product_entity_varchar AS code_business_unit
      ON main.entity_id = code_business_unit.entity_id

      LEFT JOIN catalog_product_entity_varchar AS code_line
      ON main.entity_id = code_line.entity_id

      LEFT JOIN catalog_product_entity_int AS code_group
      ON main.entity_id = code_group.entity_id

      LEFT JOIN catalog_product_entity_int AS code_business
      ON main.entity_id = code_business.entity_id


      WHERE code_brand.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_brand"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )

      AND code_business_unit.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_business_unit"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )

      AND code_line.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_line"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )


      AND code_group.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_group"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )


      AND code_business.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_business"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )


      This is what i need: i want to obtain ALL products that have these attributes:



      image



      A guy suggested me to use this query:



          SELECT 
      `e`.`sku`,
      IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
      IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

      FROM
      `catalog_product_entity` AS `e`
      INNER JOIN
      `catalog_product_entity_varchar` AS `at_name_default`
      ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND
      (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
      `at_name_default`.`store_id` = 0
      LEFT JOIN
      `catalog_product_entity_varchar` AS `at_name`
      ON (`at_name`.`entity_id` = `e`.`entity_id`) AND
      (`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
      (`at_name`.`store_id` = 1)
      INNER JOIN
      `catalog_product_entity_text` AS `at_description_default`
      ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND
      (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
      `at_description_default`.`store_id` = 0
      LEFT JOIN
      `catalog_product_entity_text` AS `at_description`
      ON (`at_description`.`entity_id` = `e`.`entity_id`) AND
      (`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
      (`at_description`.`store_id` = 1)


      The problem is that i dont fully understand how does this work.. he talked about store view for an specific id and i dont know how to do that.



      PS: i am using MAGENTO 1.9



      This is the database diagram:



      Image2









      share







      New contributor




      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am trying without success to obtain all products from MAGENTO database. (SQL only)



      After a few attempts i got this query (it is not working properly because it shows empty rows after executing it):



      SELECT 
      main.entity_id,
      main.sku,
      code_brand.value AS code_brand,
      code_business_unit.value AS code_business_unit,
      code_line.value AS code_line,
      code_group.value AS code_group,
      code_business.value AS code_business

      FROM catalog_product_entity AS main

      LEFT JOIN catalog_product_entity_int AS code_brand
      ON main.entity_id = code_brand.entity_id

      LEFT JOIN catalog_product_entity_varchar AS code_business_unit
      ON main.entity_id = code_business_unit.entity_id

      LEFT JOIN catalog_product_entity_varchar AS code_line
      ON main.entity_id = code_line.entity_id

      LEFT JOIN catalog_product_entity_int AS code_group
      ON main.entity_id = code_group.entity_id

      LEFT JOIN catalog_product_entity_int AS code_business
      ON main.entity_id = code_business.entity_id


      WHERE code_brand.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_brand"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )

      AND code_business_unit.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_business_unit"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )

      AND code_line.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_line"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )


      AND code_group.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_group"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )


      AND code_business.attribute_id = (
      SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code LIKE "code_business"
      AND 'entity_type_id' = (
      SELECT entity_type_id
      FROM eav_entity_type
      WHERE entity_type_code = 'catalog_product'
      )
      )


      This is what i need: i want to obtain ALL products that have these attributes:



      image



      A guy suggested me to use this query:



          SELECT 
      `e`.`sku`,
      IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
      IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

      FROM
      `catalog_product_entity` AS `e`
      INNER JOIN
      `catalog_product_entity_varchar` AS `at_name_default`
      ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND
      (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
      `at_name_default`.`store_id` = 0
      LEFT JOIN
      `catalog_product_entity_varchar` AS `at_name`
      ON (`at_name`.`entity_id` = `e`.`entity_id`) AND
      (`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
      (`at_name`.`store_id` = 1)
      INNER JOIN
      `catalog_product_entity_text` AS `at_description_default`
      ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND
      (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
      `at_description_default`.`store_id` = 0
      LEFT JOIN
      `catalog_product_entity_text` AS `at_description`
      ON (`at_description`.`entity_id` = `e`.`entity_id`) AND
      (`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
      (`at_description`.`store_id` = 1)


      The problem is that i dont fully understand how does this work.. he talked about store view for an specific id and i dont know how to do that.



      PS: i am using MAGENTO 1.9



      This is the database diagram:



      Image2







      magento-1.9





      share







      New contributor




      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 mins ago









      programming_amazingprogramming_amazing

      52




      52




      New contributor




      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      programming_amazing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          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
          });


          }
          });






          programming_amazing is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f259716%2fmodifying-a-query-get-products-using-sql-only%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








          programming_amazing is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          programming_amazing is a new contributor. Be nice, and check out our Code of Conduct.













          programming_amazing is a new contributor. Be nice, and check out our Code of Conduct.












          programming_amazing is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f259716%2fmodifying-a-query-get-products-using-sql-only%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

          What other Star Trek series did the main TNG cast show up in?

          Berlina muro

          Berlina aerponto