← All text tools

SQL Pattern Generator

Pick a pattern such as rank within a group, running total, percent of total, delete duplicates, upsert, pagination or recursive CTE, enter your names and get the SQL for your database.

  • Free
  • No sign-up
  • Works on any device

About SQL Pattern Generator

Window functions, recursive queries and upserts are easy to get slightly wrong, and the syntax changes from database to database. Pick a pattern and enter your table and column names: rank within a group, top N per group, first and last row, running total, percent of total, moving average, change from the previous row, find or delete duplicates, upsert, page-number and keyset pagination, recursive tree, CASE buckets, pivot with conditional sums, and EXISTS. Example: running total over amount partitioned by customer_id and ordered by created_at.

How to use SQL Pattern Generator

  1. Choose your database and the pattern you need.
  2. Fill in the table name and the columns the pattern asks for, such as the group, order and value columns.
  3. Copy the SQL and run it on sample data first. The notes below the result point out version limits and tie or NULL behaviour.

Why use this tool?

Also known as

Frequently asked questions

Which database versions do window functions need?

MySQL 8.0 or newer, SQLite 3.25 or newer, and any current version of PostgreSQL, SQL Server and Oracle. The tool adds a note when your choice depends on a version.

What is the difference between RANK and DENSE_RANK?

Both give tied rows the same number. RANK then skips numbers (1, 1, 3), while DENSE_RANK does not (1, 1, 2). ROW_NUMBER never repeats a number.

Why use keyset pagination instead of OFFSET?

OFFSET still reads every skipped row, so deep pages get slow. Keyset pagination continues after the last row you saw and stays fast, but it needs a stable order such as created_at and id.

Is SQL Pattern Generator free?

Yes. SQL Pattern Generator on Toolipedia is free to use, with no sign-up and no watermark.

Is it safe to use?

Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.

Does it work on my phone?

Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.

Do I need an account?

No. Just open the page and use the tool. There's no sign-up and no email needed.