MySQL CASE Statement

In MySQL, the CASE statement can be used in stored programs to perform a complex conditional construct. It compares a list of conditions and returns a different result depending on which condition (if any) is matched.

The CASE statement is different to the CASE operator, in that the CASE statement is specifically for use in stored programs. Also, there’s a slight difference in the syntax.

Read more

MySQL CASE Operator

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.

Read more

Find All Non-Numeric Values in a Column in SQL

If you ever encounter a character column that should be numeric, there’s always a possibility that it contains non-numeric data that you don’t know about.

For example, someone might have set up a Price column as a varchar column that should have been a numeric column, and now you need to clean up after them. You might start by identifying all non-numeric data so that you can work out what to do with it before converting the column to a numeric type.

In SQL, you can run a query to return non-numeric data from the column. The query you use will largely depend on your DBMS.

Read more

SQL CASE Statement

In SQL, the CASE statement evaluates a list of conditions and returns one of multiple possible result expressions.

In some ways, the SQL CASE statement is kind of similar to the IF...ELSE statement in that it allows us to check for a given condition and return a different result depending on the outcome.

Read more

Detect Whether a Value Contains at Least One Numerical Digit in SQL

Sometimes you might need to search a database table for only those rows that contain at least one number in a given column.

Technically, numbers can be represented by words and other symbols, but here “number” means “numerical digit”.

Below are examples of how to find rows that contain at least one number in various SQL based DBMSs.

Read more