I don't know much about Mysql and can't figure how I would achieve the following. I want to select the 50 most expensive products, and I want to order them alphabetically. The following orders them by prize, but I don't know how to grab those results and order them by something else (alphabetically).
SELECT * FROM `products` ORDER BY `prize` DESC LIMIT 50;
Try this. Would test it myself but I'm at work and we don't use MySQL here
FROM ( SELECT *
BY price DESC
LIMIT 50 )
And, for what I've read so far about mysql this is a subquery, right? I thought subqueries were only supposed to return one result. I'm confused about that.
Forgive my ignorance
No, subqueries return a result set like any other query. This set can be empty, or contain one or more rows.
Why did you think that?
actually, a subquery in the SELECT clause may return only one row consisting of one column -- i.e. a singular scalar value, which is why it's called a scalar subquery
elsewhere (e.g. in the FROM clause, or in an IN list or EXISTS predicate) a subquery can return multiple rows
Thanks a lot for the help. That's what was getting me confused. Subquries can really get quite complicated.
If someone knows of some good resources to learn about subqueries, I'll greatly appreaciate if they could link to them. I've already read the official mysql documentation.