Common Table Expressions (CTEs) are a handy way to break down a complex query into readable, reusable pieces. When you need several intermediate results – say, a filtered set, an aggregation, and a ranking – you can stack multiple CTE definitions together. PostgreSQL, SQL Server, MySQL 8+, and many other engines support this syntax.
MariaDB
Overview of the MEDIAN() Function in MariaDB
In MariaDB, the MEDIAN() function returns the median value of a range of values.
We can use the MEDIAN() function in our queries to get a column’s median value across its partition or the whole result set.
Fix ERROR 1050 “Table … already exists” in MariaDB
If you’re getting an error that reads something like “ERROR 1050 (42S01) at line 22: Table ‘Pets’ already exists” when trying to create a table in MariaDB, it’s most likely because there’s already a table in the database with the same name.
To fix this issue, either change the name of the table you’re trying to create, or check the existing table to see if it’s the one you actually need.
Get the Number of Rows Affected by Previous SQL Statement
3 Ways to Clone a Table in MariaDB using SQL
We have several options when it comes to using SQL to clone a table in MariaDB. And we have the option to clone the table with data, or without data.
Here are three SQL options for cloning a table in MariaDB.
How to Insert Multiple Rows in SQL
When working with SQL, we can use the INSERT statement to insert a new row into a table. But what if we want to insert more than one row?
Fortunately, we can still use the INSERT statement. Below is a quick example that inserts multiple rows using SQL.
Generate a CREATE TABLE Script for an Existing Table in MariaDB
We can use MariaDB’s SHOW CREATE TABLE statement to generate a CREATE TABLE script for existing tables in the database. This allows us to recreate the table without having to manually type out the table’s definition.
The statement requires SELECT privilege for the table.
7 Ways to Insert Multiple Rows in SQL
We can use the SQL INSERT statement to insert a row into a table. We can also use it to insert more than one row.
Below are seven ways to insert multiple rows into a table in SQL. Most of these examples should work in the major RDBMSs, with the possible exception of Oracle. But no worries, I’ve included an example just for Oracle.
How to Return the Definition of a Generated Column in MariaDB
If you have a table in MariaDB with a generated column, you can use the following methods to find out its definition.