Comparison Operators

The following operators are used to compare two values or two expressions. The not equal != or <> operator return true if the two values being compared are not equal else it returns false. The following query will output the value true.

SELECT (2+3) != (4 + 1.5)

The equal operator = returns true if the two values being compared are same if not it return false. The query below returns the value false.

SELECT (2+3) = (4 + 1.5)

The less than operator < returns true if the operand of left side is less than the operand on the right side of the operator. The value returned by this query is true. The less than operator can be combined with = operator so that if the value in the left side of the operator is less than or equal to the value in the right side of the operator then the query returns true.

SELECT (2+3) < (4+1.5)

The greater than operator < returns true if the operand of left side is greater than the operand on the right side of the operator. The value returned by this query is true. The greater than operator can be combined with = operator so that if the value in the left side of the operator is greater than or equal to the value in the right side of the operator then the query returns true.

SELECT (2+3) > (4+0.9)

The between operator returns true or false if the specified value is between a range of values in the query. The following are some of the example queries using between operator. This query returns true.

SELECT 5 BETWEEN 5 and 10

The following query returns true.

SELECT 10 BETWEEN 5 and 10

The following query returns true.

SELECT 'c' BETWEEN 'a' and 'd'

The following query returns true.

SELECT 'cab' BETWEEN 'aaa' and 'ddd'

The GREATEST operator returns the greatest value in the list of specified values. The following query returns 10 as the result.

SELECT GREATEST(1,10,5)

The following query returns e as the greatest value. Comparing strings using GREATEST operator is supported only in standard SQL.

#standardSQL
SELECT GREATEST('a','b','e')

The LEAST operator will return least of the set of values specified in the list. The following query returns 1 as the result.

SELECT LEAST(1,10,5)

The following query returns a as the result. This comparison is supported only in standard SQL.

#standardSQL
SELECT least('a','b','e')
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.138.195