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: SQLite
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 reading2 Ways to Return Non-Numeric Values in SQLite
The following SQLite examples return only those rows that have non-numeric values in a given column.
Continue readingReturn the First Monday of Each Month in SQLite
We can use SQLite’s DATE()
function to return the first Monday of each month for a given year, based on the date we provide.
But it’s not limited to Monday. We can also get the first Tuesday, Wednesday, Thursday, Friday, etc of each month.
Continue readingJSON_INSERT() vs JSON_SET() vs JSON_REPLACE() in SQLite
SQLite provides several functions for inserting, setting, and replacing values in a JSON document. Specifically, it provides json_insert()
, json_set()
, and json_replace()
.
These functions perform similar tasks, and you can sometimes use them interchangeably to a certain point.
But there is definitely a clear difference between each function.
Continue readingGet the First, Second, Third, or Fourth Monday of a Month in SQLite
We can use SQLite’s DATE()
function to perform calculations on a given date. One of the things we can do is return the first, second, third, or fourth instance of a given day within a given month.
Detect Whether a Value Contains at Least One Numerical Digit in SQLite
The following SQLite example returns all rows that contain at least one numerical digit.
Continue reading