SQL SELECT
Query rows from one or more tables.
SELECT [DISTINCT] column_list FROM table_name [WHERE condition] [GROUP BY columns] [HAVING condition] [ORDER BY columns] [LIMIT count];Open guide Common SQL statements and patterns, with notes for six database dialects.
Query rows from one or more tables.
SELECT [DISTINCT] column_list FROM table_name [WHERE condition] [GROUP BY columns] [HAVING condition] [ORDER BY columns] [LIMIT count];Open guide Add rows to a table.
INSERT INTO table_name (column_a, column_b) VALUES (value_a, value_b);Open guide Change values in existing rows.
UPDATE table_name SET column = value [, column = value] WHERE condition;Open guide Remove matching rows from a table.
DELETE FROM table_name WHERE condition;Open guide Insert or update rows according to a match condition; syntax differs by database.
MERGE INTO target USING source ON match_condition WHEN MATCHED THEN UPDATE SET ... WHEN NOT MATCHED THEN INSERT ...;Open guide Create a table with columns and constraints.
CREATE TABLE table_name (column_name data_type [constraint], ...);Open guide Change a table definition; supported operations vary by dialect.
ALTER TABLE table_name ADD COLUMN column_name data_type;Open guide Remove a table definition and its data.
DROP TABLE [IF EXISTS] table_name;Open guide Remove all rows efficiently where supported; transaction and identity behaviour varies.
TRUNCATE TABLE table_name;Open guide Create an index to support selected query patterns.
CREATE [UNIQUE] INDEX index_name ON table_name (column_list);Open guide Create a named query that can be referenced like a table.
CREATE VIEW view_name AS SELECT ...;Open guide Create a database where supported by the engine and current connection context.
CREATE DATABASE database_name;Open guide Combine rows from related tables using a join condition.
SELECT columns FROM left_table [INNER|LEFT|RIGHT|FULL] JOIN right_table ON condition;Open guide Combine compatible result sets; UNION removes duplicates while UNION ALL keeps them.
query_1 UNION [ALL] query_2;Open guide Define a common table expression for a single statement.
WITH cte_name AS (SELECT ...) SELECT ... FROM cte_name;Open guide Calculate values across related rows without collapsing the result set.
function(...) OVER (PARTITION BY ... ORDER BY ...);Open guide Return a value based on conditional branches.
CASE WHEN condition THEN value [ELSE value] ENDOpen guide Grant privileges to a database principal; privilege names and scope vary by engine.
GRANT privilege ON object TO principal;Open guide Remove previously granted privileges where supported.
REVOKE privilege ON object FROM principal;Open guide Begin an explicit transaction; exact keywords vary by database.
BEGIN [TRANSACTION];Open guide Make the current transaction's changes permanent.
COMMIT [TRANSACTION];Open guide Undo uncommitted changes in the current transaction where supported.
ROLLBACK [TRANSACTION];Open guide Mark a point within a transaction to which work can be rolled back.
SAVEPOINT savepoint_name;Open guide Show a query execution plan; output and options differ by engine.
EXPLAIN [options] query;Open guide Create a database principal; authentication syntax is vendor-specific.
CREATE USER user_name ...;Open guide Assign a role to a principal using database-specific syntax.
GRANT role_name TO principal;Open guide Inspect schema metadata; these commands are client-specific rather than portable SQL.
Use the database client's schema inspection command or query its information schema/catalog.Open guide Remove duplicate rows from a result set.
SELECT DISTINCT column FROM table;Open guide Filter rows using a condition.
SELECT ... FROM table WHERE condition;Open guide Group rows for aggregate calculations.
SELECT expression, aggregate(...) FROM table GROUP BY expression;Open guide Filter grouped results after aggregation.
SELECT ... GROUP BY ... HAVING condition;Open guide Sort query results by one or more expressions.
SELECT ... ORDER BY expression [ASC|DESC];Open guide Limit or skip rows; the syntax differs across database dialects.
SELECT ... ORDER BY ... LIMIT count OFFSET offset;Open guide Use a query as an expression, source or predicate inside another statement.
SELECT ... WHERE value IN (SELECT ...);Open guide Enforce data rules using NOT NULL, UNIQUE, CHECK, PRIMARY KEY and FOREIGN KEY constraints.
CREATE TABLE ... (column type NOT NULL, UNIQUE (...), CHECK (...), FOREIGN KEY (...) REFERENCES ...);Open guide Identify rows uniquely and enforce non-null uniqueness.
PRIMARY KEY (column_list)Open guide Enforce references between related tables when enabled and supported.
FOREIGN KEY (column) REFERENCES parent_table (column)Open guide Create a namespace where supported; schema semantics vary by database.
CREATE SCHEMA schema_name;Open guide Change or remove an index using engine-specific syntax.
DROP INDEX index_name; -- ALTER syntax varies by engineOpen guide Remove a view definition.
DROP VIEW [IF EXISTS] view_name;Open guide Remove a database where supported; this is destructive and often irreversible.
DROP DATABASE database_name;Open guide Undo a portion of a transaction to a savepoint where supported.
ROLLBACK TO SAVEPOINT savepoint_name;Open guide Manage database privileges; object scope, roles and syntax differ across engines.
GRANT privilege ON object TO principal;
REVOKE privilege ON object FROM principal;Open guide Return the first non-NULL value; NULL comparison rules require IS NULL / IS NOT NULL.
COALESCE(expression, fallback)Open guide Work with date/time values; function names and interval syntax are dialect-specific.
CURRENT_DATE · CURRENT_TIMESTAMP · vendor date functionsOpen guide Transform or inspect strings; function names vary by dialect.
CONCAT(...) · SUBSTRING(...) · LENGTH(...)Open guide Summarize groups with COUNT, SUM, AVG, MIN and MAX.
COUNT(*) · SUM(expression) · AVG(expression) · MIN(...) · MAX(...) Open guide Create temporary data that is scoped to a session or transaction depending on the engine.
CREATE TEMPORARY TABLE name (...);Open guide Run database logic in response to table events; trigger syntax varies substantially.
CREATE TRIGGER trigger_name ... ON table_name ...Open guide Define reusable database-side logic using vendor-specific procedural languages.
CREATE PROCEDURE / CREATE FUNCTION ...Open guide Execute a query and report actual plan statistics on engines that support it.
EXPLAIN ANALYZE query;Open guide Query metadata views to inspect tables, columns and constraints.
SELECT ... FROM information_schema.tables / columns;Open guide Configure isolation or read/write behaviour within supported transaction contexts.
SET TRANSACTION ISOLATION LEVEL ...;Open guide Coordinate concurrent access using row or table locks; syntax and isolation differ.
SELECT ... FOR UPDATE; -- support and clauses varyOpen guide Use conditional logic inside queries and data changes.
CASE WHEN condition THEN result ELSE fallback ENDOpen guide Test whether a subquery returns at least one row.
WHERE EXISTS (SELECT 1 FROM ... WHERE correlated_condition)Open guide No matching entries. Try another search.