If you’re getting “ERROR 1222 (21000): The used SELECT statements have a different number of columns” when using the UNION
clause in a MySQL query, it’s probably because the number of columns returned by each SELECT
statement is different.
Category: DBMS
Database Management Systems
Get the First Monday of a Month in SQLite
SQLite’s DATE()
function provides us with the ability to return the date of the first instance of a given day of a given month. Therefore, we can use it to return the first Monday of a given month. We can also use it to return the first Tuesday, Wednesday, Thursday, Friday, etc.
We can use DATETIME()
if we want a datetime value to be returned.
Get the Date/Time from a Unix Timestamp in SQLite
If you have a Unix timestamp, you can use SQLite’s DATETIME()
function with the unixepoch
modifier to compute the actual date and time.
You can alternatively use the DATE()
function if you only need the date to be returned. And it’s also possible to use the TIME()
function to return just the time portion.
Add Months to a Date in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more months to a date. There are several options when it comes to specifying the actual number of months.
3 Ways to Find Rows that Contain Uppercase Letters in MySQL
Here are three options for returning rows that contain uppercase characters in MySQL.
Continue reading4 Ways to List All Tables in a MariaDB Database
Below are four ways to list out the tables in a MariaDB database using SQL or the command line.
Continue readingSQLite SHOW TABLES Equivalent
SQLite doesn’t have a SHOW TABLES
statement like MySQL and MariaDB have, but it does have a similar command.
In SQLite, you can use the .tables
command to show a list of tables. You can alternatively use the table_list
pragma to do the job.
SQLite Introduces the UNIXEPOCH() Function
SQLite 3.38.0 was released on 2nd February 2022. With it came some enhancement to the date and time functions.
One of those enhancements is the addition of the UNIXEPOCH()
function. This function returns a unix timestamp. That is, the number of seconds since 1970-01-01 00:00:00 UTC.
4 Ways to Select Duplicate Rows in MariaDB
If you have a table that you suspect has duplicate rows in your MariaDB database, you can use any of the following queries to get an idea of how many rows are duplicates.
Continue readingReturn the End of the Month in SQLite
In SQLite, we can use the following method to calculate the last day of a given month.
We can base this either on the current date, or on some other specific date.
Continue reading