We’ll show why and how to get what we call “groups of groups”, or aggregations of aggregated data. It means using nested GROUP BY
queries.
Non-trivial uses of LIKE in SQL
The LIKE
operator is generally well-known. Most SQL users know how to find columns that contain a string, start with a string, or end with a string. But some of them, especially beginners, may not find obvious some other interesting uses of LIKE
.
Db2: Loop over an array
We saw in another article how to build an array from an SQL query (from each row, or from a column). This article shows how to loop over an array items.
MariaDB/MySQL: How to get the first and last day of the month
Different databases support different ways to get the first and last day of the month. Let’s see how to do it in MariaDB and MySQL.
Db2: How to create an array from a query
Db2 ordinary arrays can be constructed and populated from an SQL query. Let’s see how to do it.
SQL Server: Find users login time
Finding users who never logins is not trivial in SQL Server. But we can do it by creating a logon trigger.
SQL Server: Writing an HTML encode function
Sometimes we need to extract a text from the database to show it in a web page. The text should be showed as is, including any HTML tags and special characters. Normally the encoding is done by a web application, but there are cases when an SQL string is expected to return HTML encoded texts.
How to get the highest and lowest value in a row in SQL
It is well-known how to get the highest and lowest values in a table column, but it is a bit less known how to get the highest and lowest values in a row. Let’s see how to do it.
How to find the mode in SQL, aka MAX(COUNT(*)) not working
In statistics, the mode is the function that returns the element that appear most often in a series. This is what people try to achieve when they run MAX(COUNT(*))… and they find out that it doesn’t work. Let’s see how to obtain the mode in SQL.
SQL Server: How to count occurrences of a substring in a string
Sometimes you want to count all occurrences of a substring into a bigger string. For example, you may want to count all occurrences of a name in a text. This can be done, but it’s not straight-forward because SQL Server doesn’t have a specific function to do it.