In PostgreSQL, the CASE
expression compares a list of conditions and returns one of multiple possible result expressions.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
In PostgreSQL, the CASE
expression compares a list of conditions and returns one of multiple possible result expressions.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
The SQL Server CASE
statement evaluates a list of conditions and returns one of multiple possible result expressions.
Although it’s commonly known as the “CASE
statement”, the SQL Server documentation lists it as an expression. Plus it’s referred to as the “CASE
expression” in the SQL standard. Some other DBMSs distinguish between the CASE
statement and the CASE
expression. Either way, here’s a quick rundown on how the “CASE
statement” (or CASE
expression) works in SQL Server.
In Oracle Database, the CASE
expression compares a list of conditions and returns one of multiple possible expressions. It allows us to use IF
… THEN
… ELSE
logic in SQL statements without having to invoke procedures.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
Oracle also has a CASE
statement that’s very similar to the CASE
expression, but with some minor differences.
In PostgreSQL, the COALESCE()
operator returns the first non-null value from its list of arguments. If all arguments are null
, it returns null
.
In MySQL, the CASE
operator compares a list of conditions and returns one of multiple possible result expressions.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
MySQL also has the CASE
statement, which is slightly different to the CASE
operator. This article is about the CASE
operator.
In MariaDB, we can use the CASE
operator to compare a list of conditions and return a different result depending on which condition (if any) is matched.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
MariaDB also has the CASE
statement, which is slightly different to the CASE
operator. This article is about the CASE
operator.
Most major RDBMSs support the COALESCE()
operator, which returns the first non-null value from its list of arguments.
COALESCE()
is a SQL-standard feature (it’s included in the ISO/IEC 9075 specification).
In MariaDB, the COALESCE()
operator returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
In MySQL, the COALESCE()
operator returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
In SQL Server, the COALESCE()
expression returns its first non-null argument.
The way it works is, we pass a list of arguments to the expression, it evaluates the arguments in order and returns the current value of the first expression that initially doesn’t evaluate to NULL
.