Magento 2 product collection getSelect Order by Case unException Unknown column 'name' in 'order clause'Magento sorting collection only sorting first 20 productsSQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_id' in 'where clause'Getting custom attribute value from simple product load based on product collectionSQLSTATE[42S22]: Column not found: 1054 Unknown column 'attr_index_245.value' in 'having clause'Column not found: 1054 Unknown column 'ca.sort_order' in 'order clause' error“random” order clause added to my collectionProblem with SQLSTATE[42S22]: Column not foundMagento 2.2.6: Product collection does not apply the filterGet Top Rated Products and Order by ratingCategory page not working Magento 2 with more than 13 million products
Is leaving out prefixes like "rauf", "rüber", "rein" when describing movement considered a big mistake in spoken German?
Do electrons really perform instantaneous quantum leaps?
Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?
Installed software from source, how to say yum not to install it from package?
What does 5d4 x 10 gp mean?
Why isn't UDP with reliability (implemented at Application layer) a substitute of TCP?
How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?
I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again
Why did the Apple //e make a hideous noise if you inserted the disk upside down?
Checkmate in 1 on a Tangled Board
Does friction always oppose motion?
How can an inexperienced GM keep a game fun for experienced players?
Fast method to cut/shred glue stick into small pieces
Fully submerged water bath for stove top baking?
Why was Pan Am Flight 103 flying over Lockerbie?
Example of query execution plan where the cardinality estimation makes a difference
How far can gerrymandering go?
Russian equivalents of 能骗就骗 (if you can cheat, then cheat)
What is the meaning of 'shout over' in a sentence exactly?
Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?
Avoiding repetition when using the "snprintf idiom" to write text
Dynamic Sql Query - how to add an int to the code?
Is it advisable to inform the CEO about his brother accessing his office?
Did the Russian Empire have a claim to Sweden? Was there ever a time where they could have pursued it?
Magento 2 product collection getSelect Order by Case unException Unknown column 'name' in 'order clause'
Magento sorting collection only sorting first 20 productsSQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_id' in 'where clause'Getting custom attribute value from simple product load based on product collectionSQLSTATE[42S22]: Column not found: 1054 Unknown column 'attr_index_245.value' in 'having clause'Column not found: 1054 Unknown column 'ca.sort_order' in 'order clause' error“random” order clause added to my collectionProblem with SQLSTATE[42S22]: Column not foundMagento 2.2.6: Product collection does not apply the filterGet Top Rated Products and Order by ratingCategory page not working Magento 2 with more than 13 million products
I need to use ORDER BY CASE name which is product name
Query:
SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`,
`stock_status_index`.`stock_status` AS `is_salable`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index`
ON cat_index.product_id=e.entity_id AND cat_index.store_id=1
AND cat_index.category_id='3'
LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index`
ON e.entity_id = stock_status_index.product_id AND
stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
ORDER BY CASE WHEN `name` LIKE '%banana%' THEN 1
WHEN `name` LIKE '%apple%' THEN 2
ELSE 3 END
...name
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHENLIKE '%banana%' THEN 1 WHENnameLIKE '%apple%' THEN 2 ELSE 3 END"));
...
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'order clause'
If do setOrder instead of order then it Works but it just order alphabetically like so:
$collection->addCategoryFilter($category)->setOrder('name', 'ASC');
I need Expression what is going wrong?
database collection product-collection magento2.2.2
add a comment |
I need to use ORDER BY CASE name which is product name
Query:
SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`,
`stock_status_index`.`stock_status` AS `is_salable`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index`
ON cat_index.product_id=e.entity_id AND cat_index.store_id=1
AND cat_index.category_id='3'
LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index`
ON e.entity_id = stock_status_index.product_id AND
stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
ORDER BY CASE WHEN `name` LIKE '%banana%' THEN 1
WHEN `name` LIKE '%apple%' THEN 2
ELSE 3 END
...name
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHENLIKE '%banana%' THEN 1 WHENnameLIKE '%apple%' THEN 2 ELSE 3 END"));
...
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'order clause'
If do setOrder instead of order then it Works but it just order alphabetically like so:
$collection->addCategoryFilter($category)->setOrder('name', 'ASC');
I need Expression what is going wrong?
database collection product-collection magento2.2.2
because of name has not alias of table name so you need to specify[alias].nameinsetOrder().
– Hardik Visa
Jun 22 at 6:48
@HardikVisaSELECTe.*,cat_index.position` AScat_index_position,stock_status_index.stock_statusASis_salableFROMcatalog_product_entityASeINNER JOINcatalog_category_product_indexAScat_indexON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' LEFT JOINcataloginventory_stock_statusASstock_status_indexON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 ORDER BY CASE WHEN e.name LIKE '%banana%' THEN 1 WHEN e.name LIKE '%apple%' THEN 2 ELSE 3 END`
– Juliano Vargas
Jun 24 at 8:38
@HardikVisa Doesn't workException #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'order clause'
– Juliano Vargas
Jun 24 at 8:38
add a comment |
I need to use ORDER BY CASE name which is product name
Query:
SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`,
`stock_status_index`.`stock_status` AS `is_salable`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index`
ON cat_index.product_id=e.entity_id AND cat_index.store_id=1
AND cat_index.category_id='3'
LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index`
ON e.entity_id = stock_status_index.product_id AND
stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
ORDER BY CASE WHEN `name` LIKE '%banana%' THEN 1
WHEN `name` LIKE '%apple%' THEN 2
ELSE 3 END
...name
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHENLIKE '%banana%' THEN 1 WHENnameLIKE '%apple%' THEN 2 ELSE 3 END"));
...
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'order clause'
If do setOrder instead of order then it Works but it just order alphabetically like so:
$collection->addCategoryFilter($category)->setOrder('name', 'ASC');
I need Expression what is going wrong?
database collection product-collection magento2.2.2
I need to use ORDER BY CASE name which is product name
Query:
SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`,
`stock_status_index`.`stock_status` AS `is_salable`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index`
ON cat_index.product_id=e.entity_id AND cat_index.store_id=1
AND cat_index.category_id='3'
LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index`
ON e.entity_id = stock_status_index.product_id AND
stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
ORDER BY CASE WHEN `name` LIKE '%banana%' THEN 1
WHEN `name` LIKE '%apple%' THEN 2
ELSE 3 END
...name
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHENLIKE '%banana%' THEN 1 WHENnameLIKE '%apple%' THEN 2 ELSE 3 END"));
...
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'order clause'
If do setOrder instead of order then it Works but it just order alphabetically like so:
$collection->addCategoryFilter($category)->setOrder('name', 'ASC');
I need Expression what is going wrong?
database collection product-collection magento2.2.2
database collection product-collection magento2.2.2
asked Jun 21 at 19:36
Juliano VargasJuliano Vargas
7126 silver badges26 bronze badges
7126 silver badges26 bronze badges
because of name has not alias of table name so you need to specify[alias].nameinsetOrder().
– Hardik Visa
Jun 22 at 6:48
@HardikVisaSELECTe.*,cat_index.position` AScat_index_position,stock_status_index.stock_statusASis_salableFROMcatalog_product_entityASeINNER JOINcatalog_category_product_indexAScat_indexON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' LEFT JOINcataloginventory_stock_statusASstock_status_indexON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 ORDER BY CASE WHEN e.name LIKE '%banana%' THEN 1 WHEN e.name LIKE '%apple%' THEN 2 ELSE 3 END`
– Juliano Vargas
Jun 24 at 8:38
@HardikVisa Doesn't workException #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'order clause'
– Juliano Vargas
Jun 24 at 8:38
add a comment |
because of name has not alias of table name so you need to specify[alias].nameinsetOrder().
– Hardik Visa
Jun 22 at 6:48
@HardikVisaSELECTe.*,cat_index.position` AScat_index_position,stock_status_index.stock_statusASis_salableFROMcatalog_product_entityASeINNER JOINcatalog_category_product_indexAScat_indexON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' LEFT JOINcataloginventory_stock_statusASstock_status_indexON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 ORDER BY CASE WHEN e.name LIKE '%banana%' THEN 1 WHEN e.name LIKE '%apple%' THEN 2 ELSE 3 END`
– Juliano Vargas
Jun 24 at 8:38
@HardikVisa Doesn't workException #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'order clause'
– Juliano Vargas
Jun 24 at 8:38
because of name has not alias of table name so you need to specify
[alias].name in setOrder().– Hardik Visa
Jun 22 at 6:48
because of name has not alias of table name so you need to specify
[alias].name in setOrder().– Hardik Visa
Jun 22 at 6:48
@HardikVisa
SELECT e.*, cat_index.position` AS cat_index_position, stock_status_index.stock_status AS is_salable FROM catalog_product_entity AS e INNER JOIN catalog_category_product_index AS cat_index ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' LEFT JOIN cataloginventory_stock_status AS stock_status_index ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 ORDER BY CASE WHEN e.name LIKE '%banana%' THEN 1 WHEN e.name LIKE '%apple%' THEN 2 ELSE 3 END`– Juliano Vargas
Jun 24 at 8:38
@HardikVisa
SELECT e.*, cat_index.position` AS cat_index_position, stock_status_index.stock_status AS is_salable FROM catalog_product_entity AS e INNER JOIN catalog_category_product_index AS cat_index ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' LEFT JOIN cataloginventory_stock_status AS stock_status_index ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 ORDER BY CASE WHEN e.name LIKE '%banana%' THEN 1 WHEN e.name LIKE '%apple%' THEN 2 ELSE 3 END`– Juliano Vargas
Jun 24 at 8:38
@HardikVisa Doesn't work
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'order clause'– Juliano Vargas
Jun 24 at 8:38
@HardikVisa Doesn't work
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'order clause'– Juliano Vargas
Jun 24 at 8:38
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279236%2fmagento-2-product-collection-getselect-order-by-case-unexception-unknown-column%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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279236%2fmagento-2-product-collection-getselect-order-by-case-unexception-unknown-column%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
because of name has not alias of table name so you need to specify
[alias].nameinsetOrder().– Hardik Visa
Jun 22 at 6:48
@HardikVisa
SELECTe.*,cat_index.position` AScat_index_position,stock_status_index.stock_statusASis_salableFROMcatalog_product_entityASeINNER JOINcatalog_category_product_indexAScat_indexON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' LEFT JOINcataloginventory_stock_statusASstock_status_indexON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 ORDER BY CASE WHEN e.name LIKE '%banana%' THEN 1 WHEN e.name LIKE '%apple%' THEN 2 ELSE 3 END`– Juliano Vargas
Jun 24 at 8:38
@HardikVisa Doesn't work
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'order clause'– Juliano Vargas
Jun 24 at 8:38