Contents

Chapter 1

Reusable Query Library

A collection of SQL query patterns that work across all Retool templates. Copy these into your Retool queries and adjust table/column names for your schema.

Pagination

sql
-- Offset-based pagination (works with Retool's table component)
SELECT *
FROM your_table
ORDER BY created_at DESC
LIMIT {{table1.pageSize}}
OFFSET {{table1.paginationOffset}}
sql
-- Case-insensitive search across multiple columns
SELECT *
FROM your_table
WHERE (
  {{searchInput.value}} = ''
  OR name ILIKE '%' || {{searchInput.value}} || '%'
  OR email ILIKE '%' || {{searchInput.value}} || '%'
  OR id::text = {{searchInput.value}}
)

Date Range Filtering

sql
-- Filter by date range picker component
SELECT *
FROM your_table
WHERE created_at BETWEEN {{dateRange.start}} AND {{dateRange.end}}

Aggregation with Filters

sql
-- Dashboard statistics with conditional aggregation
SELECT
  COUNT(*) as total,
  COUNT(*) FILTER (WHERE status = 'active') as active_count,
  COUNT(*) FILTER (WHERE created_at >= CURRENT_DATE) as today_count,
  ROUND(AVG(some_metric), 2) as avg_metric
FROM your_table
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'

Upsert Pattern

sql
-- Insert or update based on a unique key
INSERT INTO your_table (unique_key, name, value, updated_at)
VALUES ({{form.data.key}}, {{form.data.name}}, {{form.data.value}}, NOW())
ON CONFLICT (unique_key) DO UPDATE SET
  name = EXCLUDED.name,
  value = EXCLUDED.value,
  updated_at = NOW()

Soft Delete

sql
-- Soft delete with audit trail
UPDATE your_table
SET
  status = 'deleted',
  deleted_at = NOW(),
  deleted_by = {{current_user.id}}
WHERE id = {{table1.selectedRow.id}}

Audit Log Insert

sql
-- Log an action to an audit trail
INSERT INTO audit_logs (user_id, action, resource_type, resource_id, metadata, ip_address, created_at)
VALUES (
  {{current_user.id}},
  'update',
  'order',
  {{table1.selectedRow.id}},
  jsonb_build_object('old_status', {{table1.selectedRow.status}}, 'new_status', {{statusSelect.value}}),
  {{current_user.ip}},
  NOW()
)

Bulk Operations

sql
-- Bulk update using selected rows from a table
UPDATE your_table
SET status = {{statusSelect.value}}, updated_at = NOW()
WHERE id = ANY(ARRAY[{{table1.selectedRows.map(r => r.id).join(',')}}]::int[])

Time-Series for Charts

sql
-- Generate time-series data for chart components
SELECT
  DATE(created_at) as date,
  COUNT(*) as count,
  SUM(amount) as total_amount
FROM your_table
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY DATE(created_at)
ORDER BY date
Chapter 2
🔒 Available in full product

Resource Configuration Guide

Chapter 3
🔒 Available in full product

Reusable Query Library

Chapter 4
🔒 Available in full product

Resource Configuration Guide

Chapter 5
🔒 Available in full product

Admin Panel — Setup Guide

Chapter 6
🔒 Available in full product

API Key Manager — Setup Guide

Chapter 7
🔒 Available in full product

Content Moderation Queue — Setup Guide

Chapter 8
🔒 Available in full product

CRM Contact Manager — Setup Guide

Chapter 9
🔒 Available in full product

Inventory Manager — Setup Guide

Chapter 10
🔒 Available in full product

Order Management Dashboard — Setup Guide

Chapter 11
🔒 Available in full product

Support Ticket System — Setup Guide

Chapter 12
🔒 Available in full product

User Analytics Dashboard — Setup Guide

You’ve reached the end of the free preview

Get the full Retool Internal Tool Templates and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $39 →
📦 Free sample included — download another copy or visit the store for the full product.
Retool Internal Tool Templates v1.0.0 — Free Preview