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

Check if more than N rows are returned

Counting the rows that match a WHERE condition can be slow, and may return a very high and precise number that is useful to no one. Let’s see how to just check if a query returns more than N rows.

Continue reading Check if more than N rows are returned
Published August 11, 2021
Categorized as Generic SQL Tagged level-intermediate

SQL Server extended properties (comments)

Most DBMSs allow to read and write comments about tables, columns and other database objects. SQL Server has a more complex feature called Extended Properties.

Continue reading SQL Server extended properties (comments)
Published August 9, 2021
Categorized as SQL Server Tagged level-intermediate

MariaDB/MySQL: Comments on database objects

MariaDB and MySQL support a non-standard syntax to read and write comments for database objects.

Continue reading MariaDB/MySQL: Comments on database objects
Published August 9, 2021
Categorized as MariaDB, MySQL Tagged level-intermediate

Comments on database objects

Why and how to write comments on database, tables, and other objects on most DBMSs. How to read comments.

Continue reading Comments on database objects
Published August 9, 2021
Categorized as Db2, Generic SQL, Oracle, PostgreSQL Tagged level-intermediate

Make searches at the end of a text fast

Searching for a string at the end of a text column is typically slow, because no index is used. How to build a suitable index and make LIKE '%end' fast.

Continue reading Make searches at the end of a text fast
Published July 28, 2021
Categorized as Generic SQL Tagged level-intermediate

Db2: Copying a table

How to create a copy of a table. The copy can contain data, a selective portion of the data, or it can be empty.

Continue reading Db2: Copying a table
Published July 27, 2021
Categorized as Db2 Tagged level-intermediate

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

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

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

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 3 Page 4 Older posts
  • Twitter
  • Email
SQL Bits
Proudly sponsored by Vettabase.