SELECT column1 FROM table WHERE column2 is greater than column1

1.6k Views Asked by At

sample table

I want to display all values of a column that is greater than its equivalent value in another row

Like for example, Display country name WHERE population is greater than country name (i.e. Andorra)

SELECT name FROM country
WHERE population > population (of Andorra)
2

There are 2 best solutions below

1
On BEST ANSWER

You can use subquery for this, e.g.:

SELECT name
FROM country
WHERE population > (
   SELECT population
   FROM country 
   WHERE name = 'Andorra'
);

Please note that this query will return an error if

  • there is no record with name country name 'Andorra' or
  • there is more than one record with country name 'Andorra'
0
On
SELECT name FROM country
WHERE population > (SELECT population FROM country WHERE name = 'Andorra')

You think something like this?