SQL Greater Than Comparison Operator

·

·

The SQL Greater Than comparison operator (>) is used to compare two values.  It returns TRUE if the first value is greater than the second.  If the second is greater, it returns FALSE. 

You can also test for greater than or equal to by using >=.  

Here are a couple of examples: 

10 > 5TRUE 
5 > 20FALSE
10 > 10FALSE

Here is an example using the SQL greater than comparison operator to find all products whose list price is greater than $3000.

SQL Greater Than example

Only rows whose ListPrice is more than $3000.00 are included in the results. Try it for your self!

SELECT ProductNumber, Name, ListPrice From Production.Product Where ListPrice > 3000
SELECT ProductNumber, Name, ListPrice 
From Production.Product 
Where ListPrice > 3000

SQL Greater Than with Other Types 

You can use the greater than comparison with other data types, such as String and DateTime

Here we’re returning products modified after February 1st, 2014.

SELECT ProductNumber, Name, ListPrice, ModifiedDate From Production.Product WHERE ModifiedDate > '2014-02-01'
SELECT ProductNumber, Name, ListPrice, ModifiedDate 
From   Production.Product 
WHERE  ModifiedDate > '2014-02-01'

When working with text values, such as names and address, keep in mind your DBMS collating order. It will affect how these operators work. In simple terms the collating order is (A-Z) ascending, but you can can that!

Additional Resources 

To learn more about greater than (>), check out these useful resources: 

More from the blog


MySQL PostgreSQL SQLite SqlServer