🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
title: Use ANY JOIN When Only One Match Needed impact: HIGH impactDescription: "Returns first match only; less memory and faster execution" tags: [query, JOIN, ANY, performance]
Use ANY JOIN When Only One Match Needed
Impact: HIGH
Use ANY JOINs when you only need a single match rather than all matches. They consume less memory and execute faster.
Incorrect (returns all matches):
-- Returns all matching rows, uses more memory
SELECT o.order_id, c.name
FROM orders o
LEFT JOIN customers c ON c.id = o.customer_id;
Correct (returns first match only):
-- Returns only first match per row, faster and less memory
SELECT o.order_id, c.name
FROM orders o
LEFT ANY JOIN customers c ON c.id = o.customer_id;
ANY JOIN types:
| Type | Behavior |
|---|---|
LEFT ANY JOIN |
At most one match from right table |
INNER ANY JOIN |
At most one match, only matching rows |
RIGHT ANY JOIN |
At most one match from left table |
Reference: Minimize and Optimize JOINs