NEW
A structured request to retrieve or manipulate data from an information system, typically a database.
DESCRIPTION
Queries express information needs to databases and other data systems using languages like SQL, SPARQL, and GraphQL. Declarative queries specify what to retrieve, leaving optimization to the system’s planner and optimizer. Read-only queries (e.g., SELECT) contrast with mutating operations (e.g., INSERT, UPDATE) and API “mutations.” Query performance depends on indexing, statistics, and execution plans. In knowledge graphs, SPARQL queries traverse triples, while GraphQL queries specify selection shapes for APIs.
ALTERNATIVE DEFINITIONS
Wikipedia
A database query is a request to access data from a database to manipulate it or retrieve it.
Covers both retrieval and manipulation within databases.
PostgreSQL
SELECT retrieves rows from zero or more tables.
Defines the canonical SQL retrieval operation from the perspective of PostgreSQL.
RELATED TERMS
SQL SELECT Data Manipulation Language DDL SPARQL GraphQL Index Query Optimizer View Stored Procedure
COMPETING TERMS
Mutation
RELATIONS
- Narrower: Federated Query Power Query
KNOWLEDGE AREAS
Programming Languages Data Storage & Operations Data Engineering Data Integration & Interoperability
TARGET AUDIENCE
Data Engineer Software Developer BI Specialist Data Analyst Data Architect Data Modeler
EXTERNAL SOURCES
- Wikipedia - Database query
- PostgreSQL - SQL SELECT reference and semantics
- Oracle - Oracle SQL SELECT statement reference
- W3C - SPARQL 1.1 Query Language standard
- GraphQL Foundation - GraphQL query and execution specification
TOP QUESTIONS
How do indexes improve Query performance?
Indexes reduce I/O by enabling fast lookups and efficient joins. Proper indexing aligns with query predicates and access patterns.
Category: Performance
What is the difference between a Query and a Mutation?
Queries read data; mutations change state. In GraphQL, the distinction is explicit, reflecting read versus write semantics.
Category: Alternatives
How do I diagnose slow Queries?
Use EXPLAIN plans, analyze indexes and statistics, and profile I/O and CPU. Optimize joins, filters, and avoid unnecessary scans.
Category: Management
What are common Query anti-patterns?
SELECT *, unbounded scans, N+1 queries in applications, and missing predicates cause performance issues. Parameterize to reuse plans.
Category: Mistakes
How do CTEs affect Query performance?
Common table expressions improve readability; materialization behavior varies by database. Benchmark to confirm performance impacts.
Category: Opinion
When to use denormalization for faster Queries?
Use denormalization for heavy read patterns and aggregations. Balance redundancy with consistency and maintenance overhead.
Category: Risk
How do Query optimizers work?
Optimizers translate SQL into execution plans using statistics, cost models, and rewrite rules to minimize estimated resource usage.
Category: Example
What is parameterized Query usage?
Parameterized queries separate code from data, enabling plan reuse and reducing SQL injection risk. They are best practice in applications.
Category: Requirements
How do Queries differ in NoSQL systems?
Many NoSQL databases use restricted query models tied to data layout, trading flexibility for scalability and predictable performance.
Category: Alternatives