Here’s an example of using SQL to find duplicate rows in a database table. This technique can be used in most of the major RDBMSs, including SQL Server, Oracle, MySQL, MariaDB, PostgreSQL, and SQLite.
SQLite
How to Convert a Unix Timestamp to a Date/Time in SQL
Here are examples of converting a Unix timestamp to a date/time value in some of the major RDBMSs.
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).
Subtract Minutes from a Time Value in SQLite
In SQLite, we can use the TIME() function to subtract one or more minutes from a time value.
For datetime values, we can use the DATETIME() function.
SQL ISNULL() Explained
Some RDBMSs provide an ISNULL() function that can be used when dealing with potentially null values.
MySQL, MariaDB, and Oracle Database each have an ISNULL() function that returns 1 if its argument is null, and 0 if it’s not.
SQL Server also has an ISNULL() function, but it works differently. It works more like how the IFNULL() function works in some other RDBMSs.
Other RDBMSs, such as PostgreSQL and SQLite don’t include an ISNULL() function, but they do support the IS NULL predicate (as do the other RDBMSs).
Add Seconds to a Time Value in SQLite
In SQLite, we can use the TIME() function to add a given number of seconds to a time value.
If we’re dealing with datetime values, we can use the DATETIME() function.
2 Ways to Get the Number of Days in a Month in SQLite
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.
SQL IFNULL() Explained
Some RDBMSs provide an IFNULL() function that can be used when dealing with potentially null values. In particular, MySQL, MariaDB, and SQLite each have an IFNULL() function that replaces any null values with another value.
Other RDBMSs, such as SQL Server, Oracle, and PostgreSQL provide similar functionality via functions of a different name.
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.