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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.