Answer the question
In order to leave comments, you need to log in
How to correctly compose an ORDER BY CASE query?
What am I doing wrong?
have a request
$query = Product::find()
->with(['image','salon'])
->joinWith('salonProduct', true, 'LEFT JOIN')
->orderBy([new \yii\db\Expression('
CASE salon_product.sort
WHEN NULL
THEN 50000
ELSE salon_product.sort
END
')]);
SELECT `product`.* FROM `product` LEFT JOIN `salon_product` ON `product`.`id` = `salon_product`.`product_id` WHERE `cat_id`='1' ORDER BY CASE WHEN salon_product.sort = NULL THEN 50000 ELSE salon_product.sort END LIMIT 24
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question