2

I need to check whether all numbers are the same. The values are coming from different columns. The signiture should allow to put any amount of columns (like the COALESCE(...) method)

SELECT equality(42, 42, 42) 

should return true and

SELECT equality(23, 42, 133)

should return false.

Is there a nice way to code this?

At time i did it like this:

SELECT (x1 = x2 AND x2 = x3);

But i hope there is a more elegant way.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
d0x
  • 11,040
  • 17
  • 69
  • 104

1 Answers1

4

Use this:

SELECT GREATEST(42, 42, 42) = LEAST(42, 42, 42)
Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252