Miscellaneous Functions

Here are three miscellaneous functions you may find useful.

GREATEST and LEAST

These functions find the GREATEST or the LEAST member from a series of expressions—for example,

SQL> SELECT GREATEST('ALPHA', 'BRAVO','FOXTROT', 'DELTA')
  2  FROM CONVERT;

GREATEST
-------
FOXTROT
FOXTROT
FOXTROT

Notice that GREATEST found the word closest to the end of the alphabet. Notice also a seemingly unnecessary FROM and three occurrences of FOXTROT. If FROM is missing, you will get an error. Every SELECT needs a FROM. The particular table used in the FROM has three rows, so the function in the SELECT clause is performed for each of them. ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.