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
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.
SELECT w1.name
FROM world w1
INNER JOIN world w2 ON w1.population > w2.population
WHERE w2.name = 'Romania'
You would probably want an index on the name field, and another index on the population field for reasonable performance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.