Mr. A Mr. A - 1 year ago 65
MySQL Question

Is there a way to shorten 'greater than' operator condition?

This is the code

SELECT name FROM world
WHERE population >
(SELECT population FROM world
WHERE name='Romania')

I want to know if the following part can be shortened.

(SELECT population FROM world
WHERE name='Romania')

I'm new to MYSQL. Sorry for such questions.

Thank You

Answer Source

While probably of little help in this query (as the sub query is only returning a single record), it is often faster to use a join rather than a sub query.

FROM world w1
INNER JOIN world w2 ON w1.population > w2.population
WHERE = 'Romania'

You would probably want an index on the name field, and another index on the population field for reasonable performance.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download