Below are examples of using SQL to return the first day of the month across various DBMSs.
This could be the first day of the current month, or the first day of a month based on a given date.
The following examples use SQL to delete duplicate rows that have a primary key or unique identifier column.
Specifically, the examples delete all duplicates except one. So for example, in the case of three identical rows, it deletes two of them and keeps one.
If you ever need to use SQL to return just the numeric values in a character column, the method you use will largely depend on your DBMS. Most DBMSs support regular expressions (regex), but some don’t. And some include functions that can detect numeric values.
Here are examples of how to do it in the more popular DBMSs.
Some DBMSs have an NVL2() function that allows us to replace a value with another value, the new value being determined by whether or not the initial value is null.
It’s similar to the NVL() function, except that NVL2() accepts exactly three arguments. This allows us to specify a different value to return in the event the first argument is not null.
In contrast, with the NVL() function, some DBMSs accept only two arguments (which makes the function a synonym for the IFNULL() function) while others accept an unlimited number of arguments (which makes it a synonym for the COALESCE() function).
Here are examples of using SQL to return duplicate rows when those rows have a primary key or other unique identifier column.
These queries work in most of the major RDBMSs, including SQL Server, Oracle, MySQL, MariaDB, PostgreSQL, and SQLite.