Create a Generated Column in MySQL

This article contains an example of adding a generated column to a table in MySQL.

Also known as computed columns, generated columns usually contain values that are dependent on other factors (such as the values in other columns).

Creating (or adding) a generated column in MySQL is basically the same as creating a normal column, except that the definition of the generated column contains an expression that determines the column’s value.

Continue reading

2 Ways to Delete Duplicate Rows in PostgreSQL (Ignoring the Primary Key)

Below are two options for removing duplicate rows from a table in PostgreSQL when those rows have a primary key or unique identifier column. The primary key is used in the query, but it’s ignored when comparing duplicates (due to the fact that primary keys prevent duplicate rows by definition).

The following examples delete duplicate rows but keep one. So in the case of say, three identical rows, it deletes two and keeps one.

Continue reading