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

Oracle: Send alerts via email

Sometimes we want to send an email when something suspicious happens in a database. Oracle is able to natively send emails.

Continue reading Oracle: Send alerts via email
Published July 27, 2021
Categorized as Oracle Tagged level-expert

Aggregate data that match a condition

How to aggregate data that match a given condition. How to perform different aggregations of data that match different conditions, in a single query. Includes convenient SQLite shortcuts.

Continue reading Aggregate data that match a condition
Published July 27, 2021
Categorized as Generic SQL, SQLite Tagged level-intermediate

Find texts that contain HTML tags

How to select text values that contain HTML tags. How to disallow inserting texts that contain HTML tags.

Continue reading Find texts that contain HTML tags
Published July 26, 2021
Categorized as Generic SQL Tagged level-beginner

Get distinct values that are stored in multiple columns

Getting a list of unique values from a column is easy. But if the same type of values are written on multiple columns and we want to eliminate duplicates, this requires a little trick.

Continue reading Get distinct values that are stored in multiple columns
Published July 26, 2021
Categorized as Generic SQL Tagged level-intermediate

SQL Server: Send alerts via email

Sometimes we want to send an email when something suspicious happens in a database. SQL Server is able to natively send emails.

Continue reading SQL Server: Send alerts via email
Published July 26, 2021
Categorized as SQL Server Tagged level-expert

Db2 triggers: FOR EACH ROW, FOR EACH STATEMENT, DB2ROW, DB2SQL

There is some confusion about the FOR EACH, the MODE, and the BEFORE / AFTER clauses of Db2 CREATE TRIGGER. While other clauses are common to most DBMSs, MODE is a Db2 unique feature. Their meaning is simpler than it seems.

Continue reading Db2 triggers: FOR EACH ROW, FOR EACH STATEMENT, DB2ROW, DB2SQL
Published July 26, 2021
Categorized as Db2 Tagged level-expert

Find rows that (don’t) contain a value from a list

How to find rows that contain, or don’t contain, a value from a list. The list may be written in the query, or stored in a table.

Continue reading Find rows that (don’t) contain a value from a list
Published July 25, 2021
Categorized as Generic SQL Tagged level-beginner

Find rows that have a match in another table

How to SELECT rows from table A that have, or don’t have, a match in table B. While doing this, we’ll keep performance in mind.

Continue reading Find rows that have a match in another table
Published July 25, 2021
Categorized as Generic SQL Tagged level-intermediate

Find the maximum text length in a column

How to get the length of the longest text in a column. Including Db2 specific syntax.

Continue reading Find the maximum text length in a column
Published July 24, 2021
Categorized as Db2, Generic SQL, Informix, MariaDB, Oracle, PostgreSQL, SQL Server Tagged level-beginner

Grouping rows by a range of values

GROUP BY allows us to group identical values to aggregate data. What is not obvious is that it can be easily used to group values that belong to the same range, as well.

Continue reading Grouping rows by a range of values
Published July 24, 2021
Categorized as Generic SQL, Informix Tagged level-intermediate

Posts navigation

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