Answer the question
In order to leave comments, you need to log in
Sorting on multiple fields?
Hello. I started writing a simple Internet store on yii, a question arose. What if there are multiple price lists. How to sort by 2 fields? I will give an example of what exactly needs to be sorted.
Here is the request:
select p.name, price1.value, price2.value
from product p
join price price1 on p.id=price1.product_id
left join price price2 on p.id=price2.product_id
order by price?.value asc
Answer the question
In order to leave comments, you need to log in
As I understand it, first the sorting is done by price1.value, then, where the values matched, we sort by price2.value
, in this case, you can simply list them in ORDER BY
select p.name, price1.value, price2.value
from product p
join price price1 on p.id=price1.product_id
left join price price2 on p.id=price2.product_id
order by price1.value asc, price2.value asc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question