Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering and limit

In a table containing cities I want to get the five biggest cities and order them by name:

SELECT * FROM cities ORDER BY population DESC LIMIT 5

That gets me the biggest cities ordered by population, but I want the same cities ordered by name. Is there an easy way to do this (without turning to a subquery or sorting the cities afterwards with PHP)?

like image 319
Jonas Avatar asked Feb 02 '10 23:02

Jonas


People also ask

What is a limit but order?

Limit order This means that your order may only be filled at your designated price or better. However, you're also directing your order to fill only if this condition occurs. Limit orders allow control over the price of an execution, but they do not guarantee that the order will be executed immediately or even at all.

What is difference between limit and market order?

Market orders are transactions meant to execute as quickly as possible at the current market price. Limit orders set the maximum or minimum price at which you are willing to complete the transaction, whether it be a buy or sell.

What is a limit order example?

A limit order is the use of a pre-specified price to buy or sell a security. For example, if a trader is looking to buy XYZ's stock but has a limit of $14.50, they will only buy the stock at a price of $14.50 or lower.

What is limit or better order?

At-or-better orders are examples of limit orders. They are executed at a specific price or above. Limit orders take longer to execute and may not even be executed because of their specific price requirements. Placing an at-or-better order is looking for a breakout and wanting to participate in the next move upwards.


1 Answers

I think what you want is this:

( SELECT * FROM cities ORDER BY population DESC LIMIT 5 ) ORDER BY name;
like image 88
ggiroux Avatar answered Nov 02 '22 06:11

ggiroux