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

Tag: level-intermediate

SQL Server: Handle errors

SQL Server allows to handle errors with TRY ... CATCH blocks, and provides several statements to get information about the error that is being handled.

Continue reading SQL Server: Handle errors
Published October 9, 2021
Categorized as SQL Server Tagged level-intermediate

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

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

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

Select values that occur multiple times

There are many cases when we want to select values that occur multiple times: customers that ordered the same product multiple times, users with the same email, and so on. We can do this with GROUP BY and HAVING.

Continue reading Select values that occur multiple times
Published August 25, 2021
Categorized as Generic SQL Tagged level-intermediate

SQL Server: CHECKSUM() vs CHECKSUM_BINARY() vs HASHBYTES()

SQL Server has at least three functions to create checksums or hashes: CHECKSUM(), CHECKSUM_BINARY(), and HASHBYTES(). Here we discuss what differences exist between them, and how to choose the proper function for a specific use case.

Continue reading SQL Server: CHECKSUM() vs CHECKSUM_BINARY() vs HASHBYTES()
Published August 22, 2021
Categorized as SQL Server Tagged level-intermediate

MariaDB: Running a prepared statement in a stored procedure

How to run prepared statements in a MariaDB stored procedure. The article covers one-off prepared statements, reusable prepared statements, and parameters.

Continue reading MariaDB: Running a prepared statement in a stored procedure
Published August 19, 2021
Categorized as MariaDB Tagged level-intermediate

PostgreSQL: Working with ENUM types

Sometimes a text column should not contain free texts, but only values from a predefined list. PostgreSQL allows to achieve this by creating an enumeration – or an ENUM type. This allows validation on input, and makes the values more efficient.

Continue reading PostgreSQL: Working with ENUM types
Published August 15, 2021
Categorized as PostgreSQL Tagged level-intermediate

Posts navigation

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