In PostgreSQL, we can use the +
operator to add one or more years to a date.
Tag: how to
Return Only Numeric Values in MySQL
The following MySQL query returns only those rows that have numeric values in a given column.
Continue reading2 Ways to Delete Duplicate Rows in Oracle
The following options can be used to delete duplicate rows in Oracle Database.
These examples delete duplicate rows but keep one. So if there are three identical rows for example, it deletes two of them and keeps one. This is often referred to as de-duping the table.
Continue readingFix “ERROR 1136 (21S01): Column count doesn’t match value count at row 2” when using the VALUES Statement in MySQL
If you’re getting an error that reads something like “ERROR 1136 (21S01): Column count doesn’t match value count at row 2” when using the VALUES
statement in MySQL, it’s probably because there’s a mismatch in the number of columns specified in the ROW()
clauses.
To fix this error, be sure that all ROW()
clauses contain exactly the same number of columns.
Get the First Monday of a Year in SQLite
We can use SQLite’s DATE()
function to return the date of the first instance of a given day of a given year. Therefore, we can use it to return the first Monday of a given year. 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.
5 Ways to Find Rows that Contain Uppercase Letters in SQL Server
Below are five options for returning rows that contain uppercase letters in SQL Server.
Continue readingHow to Wrap Long Lines of Text in SQLite Results
If you’re using one of SQLite’s tabular output modes, you might find yourself battling with long lines of text that result in all subsequent columns being pushed out far to the right. This can cause you to have to keep scrolling sideways as you peruse the data.
Fortunately, there’s an easy fix.
Continue readingPostgreSQL SHOW TABLES Equivalent (psql)
MySQL and MariaDB have a SHOW TABLES
statement, which outputs a list of tables and views in a database. PostgreSQL doesn’t have a SHOW TABLES
statement, but it does have a command that produces a similar result.
In Postgres, you can use the \dt
command to show a list of tables. This is a psql command (psql is the interactive terminal for PostgreSQL).
Format SQLite Results as JSON
It’s possible to output query results as a JSON document when using the SQLite command line interface.
We can do this with the json
output mode.
We can also use SQLite functions like json_object()
and/or json_array()
to return query results as a JSON document.
How to Format SQLite Results as a Table
SQLite has a number of tabular output modes. One of these is called table
mode.
Below is an example of using table
mode to output SQLite’s query results as a table.