Skip to content

SQL Bits

You're here to find quick SQL recipes.

  • Home
  • Topics
    • Generic SQL
    • PostgreSQL
    • MariaDB
    • MySQL
    • Oracle
    • SQL Server
    • Db2
    • Informix
    • SQLite
  • Advertising
  • Write
  • About

Db2 hash functions: HASH(), HASH4(), HASH8()

Db2 supports three different hash functions, and each of them can use different algorithms. Let’s shred some light on them to understand their use cases.

Continue reading Db2 hash functions: HASH(), HASH4(), HASH8()
Published October 2, 2021
Categorized as Db2 Tagged level-intermediate

Are RIGHT JOINs ever necessary?

RIGHT JOINs can always be rewritten as LEFT JOINs, and some people consider RIGHT JOINs a bad practice. This article explains why.

Continue reading Are RIGHT JOINs ever necessary?
Published September 30, 2021
Categorized as Generic SQL Tagged level-beginner

PostgreSQL: Making a comparison case-insensitive

In PostgreSQL, string comparisons are case-sensitive by default. Making them case-insensitive requires the ILIKE operator and may require an additional index for performance reasons.

Continue reading PostgreSQL: Making a comparison case-insensitive
Published September 26, 2021
Categorized as PostgreSQL Tagged level-beginner

Find values above the average

How to find values in a table column that are above (or below) the average of that column.

Continue reading Find values above the average
Published September 23, 2021
Categorized as Generic SQL Tagged level-beginner

SQL Server: Raise errors and warnings

Transact-SQL provides facilities to raise errors and warnings, as well as handling them. Here’s an introduction to this subject.

Continue reading SQL Server: Raise errors and warnings
Published September 22, 2021
Categorized as SQL Server Tagged level-expert

Find values that appear in multiple columns, in different rows

There are situations when you need to find values that occur in multiple columns, but oitentially in different rows. This can be done with the JOIN or the INTERSECT statement.

Continue reading Find values that appear in multiple columns, in different rows
Published September 16, 2021
Categorized as Generic SQL Tagged level-intermediate

Db2 temporary tables: ON COMMIT and ON ROLLBACK

Let’s see how to preserve, empty or drop temporary tables when a transaction succeeds (COMMIT) or fails (ROLLBACK).

Continue reading Db2 temporary tables: ON COMMIT and ON ROLLBACK
Published September 12, 2021
Categorized as Db2 Tagged level-expert

Concatenate multiple columns from the same table

Sometimes we want to concatenate multiple table columns, and see them as a single column in our resultset. This may be the case, for example, if we have columns like email1, email2, email3.

Continue reading Concatenate multiple columns from the same table
Published September 10, 2021
Categorized as Generic SQL Tagged level-intermediate

Copying tables in MariaDB and MySQL

There are many reasons why we may want to duplicate a table. We may want to copy the table structure alone, or include the rows, we may only want to copy some sample rows. Let’s see how to copy a table in MariaDB and MySQL.

Continue reading Copying tables in MariaDB and MySQL
Published September 9, 2021
Categorized as MariaDB, MySQL Tagged level-intermediate

Find dates in a given year

Sometimes we want to find all events that happened in a given year. For example, a count of the sales that happened in the year 2000. It’s frequent to run a correct query that turns out to be slow. Let’s see how to do it properly.

Continue reading Find dates in a given year
Published September 5, 2021
Categorized as Generic SQL, PostgreSQL Tagged level-intermediate

Posts navigation

Newer posts Page 1 … Page 3 … Page 7 Older posts
  • Twitter
  • Email
SQL Bits
Proudly sponsored by Vettabase.