SQL Blog

21 in-depth tutorials and references for developers who work with SQL every day. Covers MySQL, PostgreSQL, SQL Server, and SQLite.

Database Schema Design Basics — From ER Diagram to SQL

A practical guide to database schema design: extract entities from requirements, choose primary keys (auto-increment vs UUID vs natural key), set up foreign keys and ON DELETE rules, apply 1NF-3NF, and turn an ER diagram into CREATE TABLE statements.
September 11, 2026Design

How to Fix MySQL Error 1064 (Syntax Error)

MySQL error 1064 means the parser rejected your query. Learn the five most common causes — reserved words, bad quotes, typos, version syntax, comment spacing — with before/after fixes and how to catch SQL syntax errors before you run them.
September 11, 2026Errors

How Database Indexes Work — A Practical Guide

Learn how database indexes work: B+ tree storage, clustered vs secondary indexes, composite index leftmost prefix rules, covering indexes, the four cases where indexes fail, write-side cost, and verifying usage with EXPLAIN.
September 11, 2026Performance

How to Compare Two SQL Queries — Methods and Best Practices

Learn how to compare SQL queries reliably: why eyeball diffs fail, how to normalize formatting before comparing, text-level vs semantic-level SQL diff, git diff workflows, and stored procedure comparison.
September 11, 2026Comparison

How to Format SQL in DBeaver

Learn how to format SQL in DBeaver: use the built-in formatter (Ctrl+Shift+F), customize formatting profiles for indentation, keyword case and line breaks, share profiles with your team, and fix common problems.
September 11, 2026Tools

How to Generate Test Data in SQL — Sequences, Random Values, and a Million Rows

Generate test data in SQL with recursive CTEs, RAND() and random(), and foreign-key-safe related rows. Complete runnable MySQL and PostgreSQL code for a million rows.
September 11, 2026Data

How to Read an SQL EXPLAIN Plan — A Practical Guide

Learn how to read an SQL EXPLAIN plan column by column: id, select_type, table, type, key, rows, and Extra. Spot full table scans, filesorts, and missing indexes with a real before-and-after example.
September 11, 2026Performance

PostgreSQL vs MySQL — Key Syntax Differences, Side by Side

PostgreSQL vs MySQL syntax differences explained with side-by-side SQL: identifier quoting, string concatenation, SERIAL vs AUTO_INCREMENT, date functions, UPSERT, pagination, and case sensitivity.
September 11, 2026Comparison

SQL CTE (WITH Clause) Explained — From Basics to Recursive Queries

Learn SQL CTEs step by step: WITH clause syntax, chained CTEs vs nested subqueries, recursive CTE examples for number sequences and org trees, MySQL 8.0 and PostgreSQL support, and common pitfalls.
September 11, 2026Guide

SQL GROUP BY and HAVING Explained — WHERE vs HAVING with Real Examples

Learn SQL GROUP BY and HAVING with real order data: the execution order (FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY), why WHERE cannot use aggregates, COUNT(*) vs COUNT(col) vs COUNT(DISTINCT col), and GROUP_CONCAT.
September 11, 2026Guide

SQL Injection Prevention — How to Write Safe Queries

Practical SQL injection prevention for developers: how the classic ' OR '1'='1 payload breaks a concatenated query, why parameterized queries fix it at the root, and a hardening checklist for real apps.
September 11, 2026Security

SQL JOIN Types Explained with Examples — INNER, LEFT, RIGHT, FULL, CROSS & SELF

All 7 SQL join types explained with runnable examples and exact result tables: INNER, LEFT, RIGHT, FULL OUTER, CROSS, SELF joins plus semi-joins (EXISTS). Includes the WHERE-clause trap that silently turns LEFT JOIN into INNER JOIN.
September 11, 2026Guide

SQL NULL Handling — Common Pitfalls and Fixes

How NULL really behaves in SQL: three-valued logic, why = NULL never matches, the NOT IN trap, COUNT(col) vs COUNT(*), COALESCE across MySQL, PostgreSQL, Oracle and SQL Server, NULL sorting, and NOT NULL defaults.
September 11, 2026Guide

Subquery vs JOIN — When to Use Each (With Performance Analysis)

Subquery vs JOIN explained with runnable examples: the semantic difference, why correlated subqueries hurt, IN vs EXISTS including the NOT IN NULL trap, and how to verify with EXPLAIN.
September 11, 2026Comparison

SQL Window Functions — ROW_NUMBER, RANK, LAG and Practical Examples

Learn SQL window functions with practical examples: ROW_NUMBER OVER PARTITION BY for Top-N queries, RANK vs DENSE_RANK with ties, LAG/LEAD for month-over-month growth, running totals and frame clauses. Works in MySQL 8+ and PostgreSQL.
September 11, 2026Guide

SQL Date Format Guide — Format Dates in MySQL, PostgreSQL, SQL Server & Oracle

Comprehensive SQL date format guide. Learn how to format dates and datetimes in MySQL (DATE_FORMAT), PostgreSQL (TO_CHAR), SQL Server (FORMAT/CONVERT), and Oracle (TO_CHAR). Convert strings to dates, handle dd/mm/yyyy, and more.
August 4, 2026Reference

SQL Cheat Sheet — Quick Reference Guide for Beginners

The ultimate SQL cheat sheet with 50+ essential commands, syntax examples, and quick-reference tables. Covers SELECT, JOIN, GROUP BY, subqueries, window functions, and more for MySQL, PostgreSQL, and T-SQL.
July 14, 2026Reference

SQL Formatting Best Practices — 10 Rules for Clean, Readable SQL

Master SQL formatting with these 10 proven best practices. Learn how to write clean, readable SQL queries that your team will thank you for. Includes examples for MySQL, PostgreSQL, and T-SQL.
July 14, 2026Best Practices

SQL Query Optimization — 10 Tips to Write Faster Queries

Speed up your SQL queries with these 10 proven optimization techniques. Learn index strategies, avoiding SELECT *, efficient JOINs, EXPLAIN plans, and more for MySQL, PostgreSQL, and T-SQL.
July 14, 2026Performance

VSCode SQL Formatter — The Complete Setup Guide

Learn how to set up a VSCode SQL formatter step by step. Compare the best VS Code SQL formatting extensions — SQL Formatter, Prettier, and more — and format SQL instantly online.
July 8, 2026Tools

How to Format SQL in SSMS (SQL Server Management Studio)

Learn how to format SQL in SSMS (SQL Server Management Studio). Step-by-step guide with built-in shortcuts, third-party tools, and our free online SQL formatter for T-SQL.
July 7, 2026Tools