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













0















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


...
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHEN
nameLIKE '%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?










share|improve this question






















  • 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 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















0















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


...
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHEN
nameLIKE '%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?










share|improve this question






















  • 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 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













0












0








0








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


...
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHEN
nameLIKE '%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?










share|improve this question














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


...
$collection->addCategoryFilter($category)
$collection->getSelect()->order(new Zend_Db_Expr("CASE WHEN
nameLIKE '%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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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].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 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

















  • 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 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
















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










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%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















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%2f279236%2fmagento-2-product-collection-getselect-order-by-case-unexception-unknown-column%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

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림