magento2 join queryMagento2 Need to filter grid when value is entered in search box, the column of the data is from another tableExport from the database brand, quantity and size/color varchar: MySQL & EEComplex custom collection join problemHow to add extension attributes to Customer entity in Magento2?How to optimize the query: the product qty bought with each of the productsForeach loop taking long time in magento product collection with limitmagento2 Item (MagentoSalesModelOrder) with the same id “x” already existConfigurable Product MSRPMagento 2.2.5: how to query in observer best practiceMagento 2 : Custom Report with Two Table Join issueMagento 2 Join with ProductRepositoryInterface

I have a domain, static IP address and many devices I'd like to access outside my house. How do I route them?

Why did computer video outputs go from digital to analog, then back to digital?

Bug in Lualatex: not printing characters from calculation

Short story about a group of sci-fi writers sitting around discussing their profession

what to say when a company asks you why someone (a friend) who was fired left?

Why must API keys be kept private?

What is an Eternal Word™?

dos2unix is unable to convert typescript file to unix format

Can GPL and BSD licensed applications be used for government work?

Inverse Colombian Function

Considerations when providing money to one child now, and the other later?

High income and difficulty during interviews

Why are there not any MRI machines available in Interstellar?

What is the best word describing the nature of expiring in a short amount of time, connoting "losing public attention"?

Company requiring me to let them review research from before I was hired

How do changes to your speed that occur on your own turn affect your available movement?

Sextortion with actual password not found in leaks

Grid/table with lots of buttons

Raw curve25519 public key points

Can I pay with HKD in Macau or Shenzhen?

Are rockets faster than airplanes?

Why did NASA use Imperial units?

What would be the side effects on the life of a person becoming indestructible?

Invert Some Switches on a Switchboard



magento2 join query


Magento2 Need to filter grid when value is entered in search box, the column of the data is from another tableExport from the database brand, quantity and size/color varchar: MySQL & EEComplex custom collection join problemHow to add extension attributes to Customer entity in Magento2?How to optimize the query: the product qty bought with each of the productsForeach loop taking long time in magento product collection with limitmagento2 Item (MagentoSalesModelOrder) with the same id “x” already existConfigurable Product MSRPMagento 2.2.5: how to query in observer best practiceMagento 2 : Custom Report with Two Table Join issueMagento 2 Join with ProductRepositoryInterface






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to join the main table code with the product_options value giftcard_created_codes



My query till now



$this->getSelect()->joinLeft(['secondTable' => $this->getTable('sales_order_item')], "secondTable.product_options = main_table.code ", ['secondTable.product_options as product_options']);


product_options value



"info_buyRequest":"uenc":"aHR0cDovLzE5Mi4xNjguMS4xODQvZGcvZHJ1bW1vbmQtZ29sZi1lLWdpZnQtY2FyZC5odG1s","product":"76450","selected_configurable_option":"","related_product":"","giftcard_amount":"5","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","qty":"1","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":"0","email_sent":0,"giftcard_created_codes":["HQE9EMUNTA6N"]


enter image description here



enter image description here










share|improve this question
























  • please add structure of your main_table

    – user4536
    Jul 15 at 9:09











  • Added in my question you can verify

    – Arjun
    Jul 15 at 9:14











  • i have posted the solution, please accept and upvote if it solve your problem

    – user4536
    Jul 15 at 9:43

















1















I want to join the main table code with the product_options value giftcard_created_codes



My query till now



$this->getSelect()->joinLeft(['secondTable' => $this->getTable('sales_order_item')], "secondTable.product_options = main_table.code ", ['secondTable.product_options as product_options']);


product_options value



"info_buyRequest":"uenc":"aHR0cDovLzE5Mi4xNjguMS4xODQvZGcvZHJ1bW1vbmQtZ29sZi1lLWdpZnQtY2FyZC5odG1s","product":"76450","selected_configurable_option":"","related_product":"","giftcard_amount":"5","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","qty":"1","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":"0","email_sent":0,"giftcard_created_codes":["HQE9EMUNTA6N"]


enter image description here



enter image description here










share|improve this question
























  • please add structure of your main_table

    – user4536
    Jul 15 at 9:09











  • Added in my question you can verify

    – Arjun
    Jul 15 at 9:14











  • i have posted the solution, please accept and upvote if it solve your problem

    – user4536
    Jul 15 at 9:43













1












1








1








I want to join the main table code with the product_options value giftcard_created_codes



My query till now



$this->getSelect()->joinLeft(['secondTable' => $this->getTable('sales_order_item')], "secondTable.product_options = main_table.code ", ['secondTable.product_options as product_options']);


product_options value



"info_buyRequest":"uenc":"aHR0cDovLzE5Mi4xNjguMS4xODQvZGcvZHJ1bW1vbmQtZ29sZi1lLWdpZnQtY2FyZC5odG1s","product":"76450","selected_configurable_option":"","related_product":"","giftcard_amount":"5","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","qty":"1","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":"0","email_sent":0,"giftcard_created_codes":["HQE9EMUNTA6N"]


enter image description here



enter image description here










share|improve this question
















I want to join the main table code with the product_options value giftcard_created_codes



My query till now



$this->getSelect()->joinLeft(['secondTable' => $this->getTable('sales_order_item')], "secondTable.product_options = main_table.code ", ['secondTable.product_options as product_options']);


product_options value



"info_buyRequest":"uenc":"aHR0cDovLzE5Mi4xNjguMS4xODQvZGcvZHJ1bW1vbmQtZ29sZi1lLWdpZnQtY2FyZC5odG1s","product":"76450","selected_configurable_option":"","related_product":"","giftcard_amount":"5","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","qty":"1","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":"0","email_sent":0,"giftcard_created_codes":["HQE9EMUNTA6N"]


enter image description here



enter image description here







magento2 query join






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 15 at 13:07









Raj Mohan R

1,6993 silver badges13 bronze badges




1,6993 silver badges13 bronze badges










asked Jul 15 at 8:46









ArjunArjun

1,98410 silver badges26 bronze badges




1,98410 silver badges26 bronze badges












  • please add structure of your main_table

    – user4536
    Jul 15 at 9:09











  • Added in my question you can verify

    – Arjun
    Jul 15 at 9:14











  • i have posted the solution, please accept and upvote if it solve your problem

    – user4536
    Jul 15 at 9:43

















  • please add structure of your main_table

    – user4536
    Jul 15 at 9:09











  • Added in my question you can verify

    – Arjun
    Jul 15 at 9:14











  • i have posted the solution, please accept and upvote if it solve your problem

    – user4536
    Jul 15 at 9:43
















please add structure of your main_table

– user4536
Jul 15 at 9:09





please add structure of your main_table

– user4536
Jul 15 at 9:09













Added in my question you can verify

– Arjun
Jul 15 at 9:14





Added in my question you can verify

– Arjun
Jul 15 at 9:14













i have posted the solution, please accept and upvote if it solve your problem

– user4536
Jul 15 at 9:43





i have posted the solution, please accept and upvote if it solve your problem

– user4536
Jul 15 at 9:43










2 Answers
2






active

oldest

votes


















0














Try something like below.



$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('sales_order_item')],
new Zend_Db_Expr("JSON_UNQUOTE(json_extract(secondTable.product_options, '$.giftcard_created_codes[0]')) = main_table.code"),
['secondTable.product_options as product_options']);





share|improve this answer

























  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:39











  • missed semi colon in second argument, edited the answer.

    – Yash Shah
    Jul 15 at 9:40











  • i used your code but it keeps on continuous loading

    – Arjun
    Jul 15 at 10:05











  • Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

    – Yash Shah
    Jul 15 at 10:07











  • By the way what do you want from sales_order_item ? i dont understand your requirement ...

    – Yash Shah
    Jul 15 at 10:09


















0














$subquery = new Zend_Db_Expr("select json_extract(product_options, '$.giftcard_created_codes') from sales_order_item");
$this->getSelect()->join(['sq' => $subquery], "main_table.code = sq.value", []);





share|improve this answer

























  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:45











  • i have updated my answer check now

    – user4536
    Jul 15 at 9:52











  • Parse error: syntax error, unexpected '$', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:58











  • please check now

    – user4536
    Jul 15 at 10:02











  • Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

    – Arjun
    Jul 15 at 10:04













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%2f282069%2fmagento2-join-query%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try something like below.



$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('sales_order_item')],
new Zend_Db_Expr("JSON_UNQUOTE(json_extract(secondTable.product_options, '$.giftcard_created_codes[0]')) = main_table.code"),
['secondTable.product_options as product_options']);





share|improve this answer

























  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:39











  • missed semi colon in second argument, edited the answer.

    – Yash Shah
    Jul 15 at 9:40











  • i used your code but it keeps on continuous loading

    – Arjun
    Jul 15 at 10:05











  • Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

    – Yash Shah
    Jul 15 at 10:07











  • By the way what do you want from sales_order_item ? i dont understand your requirement ...

    – Yash Shah
    Jul 15 at 10:09















0














Try something like below.



$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('sales_order_item')],
new Zend_Db_Expr("JSON_UNQUOTE(json_extract(secondTable.product_options, '$.giftcard_created_codes[0]')) = main_table.code"),
['secondTable.product_options as product_options']);





share|improve this answer

























  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:39











  • missed semi colon in second argument, edited the answer.

    – Yash Shah
    Jul 15 at 9:40











  • i used your code but it keeps on continuous loading

    – Arjun
    Jul 15 at 10:05











  • Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

    – Yash Shah
    Jul 15 at 10:07











  • By the way what do you want from sales_order_item ? i dont understand your requirement ...

    – Yash Shah
    Jul 15 at 10:09













0












0








0







Try something like below.



$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('sales_order_item')],
new Zend_Db_Expr("JSON_UNQUOTE(json_extract(secondTable.product_options, '$.giftcard_created_codes[0]')) = main_table.code"),
['secondTable.product_options as product_options']);





share|improve this answer















Try something like below.



$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('sales_order_item')],
new Zend_Db_Expr("JSON_UNQUOTE(json_extract(secondTable.product_options, '$.giftcard_created_codes[0]')) = main_table.code"),
['secondTable.product_options as product_options']);






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 15 at 9:40

























answered Jul 15 at 9:36









Yash ShahYash Shah

1,2082 silver badges12 bronze badges




1,2082 silver badges12 bronze badges












  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:39











  • missed semi colon in second argument, edited the answer.

    – Yash Shah
    Jul 15 at 9:40











  • i used your code but it keeps on continuous loading

    – Arjun
    Jul 15 at 10:05











  • Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

    – Yash Shah
    Jul 15 at 10:07











  • By the way what do you want from sales_order_item ? i dont understand your requirement ...

    – Yash Shah
    Jul 15 at 10:09

















  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:39











  • missed semi colon in second argument, edited the answer.

    – Yash Shah
    Jul 15 at 9:40











  • i used your code but it keeps on continuous loading

    – Arjun
    Jul 15 at 10:05











  • Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

    – Yash Shah
    Jul 15 at 10:07











  • By the way what do you want from sales_order_item ? i dont understand your requirement ...

    – Yash Shah
    Jul 15 at 10:09
















I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

– Arjun
Jul 15 at 9:39





I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

– Arjun
Jul 15 at 9:39













missed semi colon in second argument, edited the answer.

– Yash Shah
Jul 15 at 9:40





missed semi colon in second argument, edited the answer.

– Yash Shah
Jul 15 at 9:40













i used your code but it keeps on continuous loading

– Arjun
Jul 15 at 10:05





i used your code but it keeps on continuous loading

– Arjun
Jul 15 at 10:05













Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

– Yash Shah
Jul 15 at 10:07





Can you please print the query and paste the sql here ? also execute that sql in your mysql and check if you get appropriate data or not ?

– Yash Shah
Jul 15 at 10:07













By the way what do you want from sales_order_item ? i dont understand your requirement ...

– Yash Shah
Jul 15 at 10:09





By the way what do you want from sales_order_item ? i dont understand your requirement ...

– Yash Shah
Jul 15 at 10:09













0














$subquery = new Zend_Db_Expr("select json_extract(product_options, '$.giftcard_created_codes') from sales_order_item");
$this->getSelect()->join(['sq' => $subquery], "main_table.code = sq.value", []);





share|improve this answer

























  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:45











  • i have updated my answer check now

    – user4536
    Jul 15 at 9:52











  • Parse error: syntax error, unexpected '$', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:58











  • please check now

    – user4536
    Jul 15 at 10:02











  • Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

    – Arjun
    Jul 15 at 10:04















0














$subquery = new Zend_Db_Expr("select json_extract(product_options, '$.giftcard_created_codes') from sales_order_item");
$this->getSelect()->join(['sq' => $subquery], "main_table.code = sq.value", []);





share|improve this answer

























  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:45











  • i have updated my answer check now

    – user4536
    Jul 15 at 9:52











  • Parse error: syntax error, unexpected '$', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:58











  • please check now

    – user4536
    Jul 15 at 10:02











  • Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

    – Arjun
    Jul 15 at 10:04













0












0








0







$subquery = new Zend_Db_Expr("select json_extract(product_options, '$.giftcard_created_codes') from sales_order_item");
$this->getSelect()->join(['sq' => $subquery], "main_table.code = sq.value", []);





share|improve this answer















$subquery = new Zend_Db_Expr("select json_extract(product_options, '$.giftcard_created_codes') from sales_order_item");
$this->getSelect()->join(['sq' => $subquery], "main_table.code = sq.value", []);






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 15 at 10:00

























answered Jul 15 at 9:41









user4536user4536

3631 silver badge15 bronze badges




3631 silver badge15 bronze badges












  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:45











  • i have updated my answer check now

    – user4536
    Jul 15 at 9:52











  • Parse error: syntax error, unexpected '$', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:58











  • please check now

    – user4536
    Jul 15 at 10:02











  • Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

    – Arjun
    Jul 15 at 10:04

















  • I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:45











  • i have updated my answer check now

    – user4536
    Jul 15 at 9:52











  • Parse error: syntax error, unexpected '$', expecting ',' or ')'

    – Arjun
    Jul 15 at 9:58











  • please check now

    – user4536
    Jul 15 at 10:02











  • Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

    – Arjun
    Jul 15 at 10:04
















I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

– Arjun
Jul 15 at 9:45





I got error Parse error: syntax error, unexpected '[', expecting ',' or ')'

– Arjun
Jul 15 at 9:45













i have updated my answer check now

– user4536
Jul 15 at 9:52





i have updated my answer check now

– user4536
Jul 15 at 9:52













Parse error: syntax error, unexpected '$', expecting ',' or ')'

– Arjun
Jul 15 at 9:58





Parse error: syntax error, unexpected '$', expecting ',' or ')'

– Arjun
Jul 15 at 9:58













please check now

– user4536
Jul 15 at 10:02





please check now

– user4536
Jul 15 at 10:02













Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

– Arjun
Jul 15 at 10:04





Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064

– Arjun
Jul 15 at 10:04

















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%2f282069%2fmagento2-join-query%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

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?