Here are two options for returning the number of days in a given month in SQLite. This could be the number of days in the current month, or it could be based on a given date.
Continue readingTag: how to
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.
Continue readingFind Values That Don’t Contain Numbers in SQL
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 reading6 Ways to Delete Duplicate Rows that have a Primary Key in Oracle
Here are some options for deleting duplicate rows from a table in Oracle Database when those rows have a primary key or unique identifier column.
In such cases, the primary key must be ignored when comparing duplicate rows (due to the fact that primary keys hold unique values).
Continue readingDetect 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 readingHow to Convert a Unix Timestamp to a Date/Time Value in PostgreSQL
In PostgreSQL, we can use the to_timestamp()
function to convert a Unix timestamp value to a date/time value.
The Unix timestamp (also known as Unix Epoch time, Unix time, or POSIX time) is the number of seconds that have elapsed since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC).
Continue reading4 Ways to Find Rows that Contain Uppercase Letters in MariaDB
Here are four options for returning rows that contain uppercase characters in MariaDB.
Continue reading2 Ways to Return Rows that Contain Non-Alphanumeric Characters in PostgreSQL
Below are two options for returning rows that only contain non-alphanumeric characters in PostgreSQL.
Non-alphanumeric characters include punctuation characters like !@#&()–[{}]:;',?/*
and symbols like `~$^+=<>“
, as well as whitespace characters like the space or tab characters.
2 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 readingSubtract Weeks from a Date in PostgreSQL
We can use the -
operator to subtract one or more weeks from a date in PostgreSQL.