If you have a column in a database table that contains character data, but some rows also contain numbers, you can use the following SQL queries to return just those rows that don’t contain numbers within the value.
Continue readingCategory: MySQL
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.
SQL NULLIF() Explained
Most major RDBMSs support the NULLIF()
operator, which returns NULL
if both of its arguments are equivalent. If the arguments not equivalent, NULLIF()
returns the first argument.
NULLIF()
is a SQL-standard feature (it’s included in the ISO/IEC 9075 specification).
SQL COALESCE() Explained
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).
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.
Continue readingMySQL IFNULL() Explained
MySQL has an IFNULL()
function that allows us to easily replace NULL values with another value.
MySQL ISNULL() Explained
In MySQL, the ISNULL()
function enables us to check whether a value is null
or not. If it’s null
, then 1
is returned, otherwise 0
is returned.
MySQL IF() Function Explained
MySQL has an IF()
function that provides a convenient way to perform a simple “IF/ELSE” operation.
It works similar to a basic IF
/ELSE
statement, in that it allows us to check for a condition, and return a different result depending on whether it’s true or not.
More specifically, if the first argument to the IF()
function is true, the second argument is returned. If it’s not true, the third argument is returned.
MySQL NULLIF() Explained
In MySQL, NULLIF()
is a flow control function that returns NULL
if both of its arguments are equivalent. Otherwise it returns the first argument.
How to Get the Number of Days in a Month in MySQL
Check out the following technique in MySQL if you need to find out how many days are in a month based on a given date.
Continue reading