0

What does <> do in the following WHERE clause,

WHERE posn_id <> rid
Evan Carroll
  • 65,432
  • 50
  • 254
  • 507
Hari
  • 33
  • 2

2 Answers2

14
 WHERE posn_id <> rid

Will return all rows where both posn_id and rid are not NULL and where they are different.

It's the ANSI SQL-Compliant not equals operator in a simple comparison predicate (WHERE statement). Colloquially, it's the "inequality operator". Though many databases accept an alternative !=, the spec itself does not mention != and it should not be used if <> is supported.

SQL uses three valued logic, with possible values being true, false or unknown. The WHERE clause filters out all rows except those where the predicate evaluates to true.

  • If either or both sides are null, the operator returns unknown.
  • On inequality, where both sides are not =, the operator returns true.
  • On equality, <> returns false.

On null treatment, a similar operator is IS DISTINCT FROM which treats nulls as ordinary values, from the PostgreSQL docs

For non-null inputs, IS DISTINCT FROM is the same as the <> operator. However, if both inputs are null it returns false, and if only one input is null it returns true.

For RDBMS specific documentation on comparison operators, see also

ypercubeᵀᴹ
  • 99,450
  • 13
  • 217
  • 306
BradC
  • 10,073
  • 9
  • 51
  • 89
2

It's just another way of spelling the "not equals" operator, an alternative to !=

mustaccio
  • 28,207
  • 24
  • 60
  • 76