Standard JOIN Types
INNER JOIN
Return rows with matching values in both tables:LEFT JOIN
Return all rows from left table, with matching rows from right:CROSS JOIN
Cartesian product of both tables:ASOF JOIN
ASOF JOIN matches rows based on temporal proximity. It joins each row from the left table with the most recent row from the right table where the timestamp is less than or equal to the left row’s timestamp.Basic ASOF JOIN
ASOF JOIN with Multiple Columns
ASOF JOIN Use Cases
- Join trades with market prices at time of trade
- Correlate sensor readings with reference measurements
- Match events with most recent state changes
LT JOIN (Less Than)
LT JOIN is an alias for ASOF JOIN:WINDOW JOIN
WINDOW JOIN aggregates data from the right table within a time window around each left table row. This enables time-window analytics like moving averages.Basic WINDOW JOIN
Include Prevailing
By default, WINDOW JOIN excludes rows before the window start. UseINCLUDE PREVAILING to include the most recent row before the window:
WINDOW JOIN Without Key
Omit the ON clause to aggregate all rows in the time window:WINDOW JOIN Use Cases
- Calculate moving averages
- Compute rolling volatility
- Aggregate metrics within time windows
- Time-windowed anomaly detection
HORIZON JOIN
HORIZON JOIN aggregates data across multiple time offsets. It evaluates aggregations at regular intervals relative to each left table row.Basic HORIZON JOIN
HORIZON JOIN with LIST
Specify specific offsets instead of a range:HORIZON JOIN Use Cases
- Multi-horizon forecasting analysis
- Event impact analysis at multiple time offsets
- Cross-correlation studies
- Lead/lag analysis
JOIN Performance Tips
Use Indexed SYMBOL Columns
Filter Before Joining
Designated Timestamps
Both tables should have designated timestamp columns for optimal time-series join performance:JOIN Limitations
- HORIZON JOIN cannot combine with other JOINs: HORIZON JOIN must be the only join in the query
- Right table must have timestamp: Time-series joins require the right table to have a designated timestamp column
- No FULL OUTER JOIN: QuestDB does not support FULL OUTER JOIN
- No RIGHT JOIN: Use LEFT JOIN with reversed table order instead
Examples
Calculate Trade Value with Latest Price
Rolling 5-Minute Average
Multi-Offset Price Analysis
Next Steps
- Time-Series Functions - Learn SAMPLE BY and LATEST ON
- Aggregations - Master aggregate functions
- Window Functions - Use analytical window functions