Chuyển tới nội dung chính
kitlocal.dev

Sổ tay cú pháp SQL

Chạy cục bộ

Xử lý 100% ngay trong trình duyệt. Dữ liệu đầu vào và kết quả không rời khỏi thiết bị.

Tra cứu nhanh các mẫu câu lệnh SQL thông dụng như JOIN, GROUP BY, Window Function, CTE và UPSERT

Cách hoạt động

SQL evaluates logically as FROM/JOIN -> WHERE -> GROUP BY -> HAVING -> SELECT/WINDOW -> DISTINCT -> ORDER BY -> LIMIT, even though `SELECT` is written first.

Bộ lệnh sống còn

Vài lệnh nên học trước tiên.

42 lệnh

Phím tắt/Tìm kiếmJKDi chuyển mục chọnCSao chép lệnh đang chọnFĐánh dấu mục đang chọnEscXoá tìm kiếm

Select, Filter & Pagination

Filter predicates safely, avoid NULL traps, sort, and paginate efficiently.

  • Cơ bản

    Filter rows, sort deterministically, and cap returned rows

    SELECT <cols> FROM <table> WHERE <cond> ORDER BY <col> DESC LIMIT <n>;

    Dựng lệnh

    SELECT <cols> FROM <table> WHERE <cond> ORDER BY <col> DESC LIMIT <n>;

    Giá trị được chèn đúng như bạn nhập. Hãy tự đặt dấu nháy nếu giá trị có khoảng trắng hoặc ký tự đặc biệt.

    Khi nào dùng

    Adding a tie-breaker column to `ORDER BY` guarantees repeatable pagination order.

    Ví dụ

    SELECT id, email, created_at FROM users WHERE status = 'active' ORDER BY created_at DESC, id DESC LIMIT 25;

Joins & Set Operations

Combine related tables cleanly and find orphan or unmatched rows.

Aggregation, CTEs & Window Functions

Group metrics, stage readable queries with CTEs, and rank without collapsing rows.

Insert, Upsert, Update & Delete

Write idempotent mutations safely inside transactions without locking accidents.

Schema, Constraints, JSON & Performance

Design tables, composite indexes, JSON queries, and inspect EXPLAIN plans.

Dùng thử trong công cụ KitLocal

Kiểm tra ngày 15 thg 11, 2026 · Đối chiếu với ANSI SQL + PostgreSQL 17 / MySQL 8.4 / SQLite 3.45 notes

Nguồn: PostgreSQL 17 Documentation · SQLite SQL Syntax · MySQL 8.4 Reference Manual

Hãy thay phần trong dấu ngoặc nhọn bằng giá trị của bạn. Lệnh lấy từ tài liệu chính thức, ví dụ đã được chạy thử trên phiên bản được ghi.