@@ -34,7 +34,7 @@ High-level overview:
3434
3535 - ` ASOF ` , ` LT ` , and ` SPLICE ` ` JOIN ` has optional ` ON ` clause allowing only the
3636 ` = ` predicate.
37- - ` ASOF ` additionally allows an optional ` TOLERANCE ` clause:
37+ - ` ASOF ` and ` LT ` join additionally allows an optional ` TOLERANCE ` clause:
3838
3939 ![ Flow chart showing the syntax of the ASOF, LT, and SPLICE JOIN keyword] ( /images/docs/diagrams/AsofLtSpliceJoin.svg )
4040
@@ -312,7 +312,7 @@ WHERE t.timestamp < t2.timestamp
312312
313313## LT JOIN
314314
315- Similar to ` ASOF JOIN ` , ` LT JOIN ` joins two different time-series measured. For
315+ Similar to [ ` ASOF JOIN ` ] ( /docs/reference/sql/asof-join/ ) , ` LT JOIN ` joins two different time-series measured. For
316316each row in the first time-series, the ` LT JOIN ` takes from the second
317317time-series a timestamp that meets both of the following criteria:
318318
@@ -395,6 +395,42 @@ order to get preceding values for every row.
395395The ` ON ` clause can also be used in combination with ` LT JOIN ` to join both by
396396timestamp and column values.
397397
398+ ### TOLERANCE clause
399+ The ` TOLERANCE ` clause enhances LT JOIN by limiting how far back in time the join should look for a match in the right
400+ table. The ` TOLERANCE ` parameter accepts a time interval value (e.g., 2s, 100ms, 1d).
401+
402+ When specified, a record from the left table t1 at t1.ts will only be joined with a record from the right table t2 at
403+ t2.ts if both conditions are met: ` t2.ts < t1.ts ` and ` t1.ts - t2.ts <= tolerance_value `
404+
405+ This ensures that the matched record from the right table is not only the latest one on or before t1.ts, but also within
406+ the specified time window.
407+
408+ ``` questdb-sql title="LT JOIN with a TOLERANCE parameter"
409+ SELECT ...
410+ FROM table1
411+ LT JOIN table2 TOLERANCE 10s
412+ [WHERE ...]
413+ ```
414+
415+ The interval_literal must be a valid QuestDB interval string, like '5s' (5 seconds), '100ms' (100 milliseconds),
416+ '2m' ( 2 minutes), '3h' (3 hours), or '1d' (1 day).
417+
418+ #### Supported Units for interval_literal
419+ The ` TOLERANCE ` interval literal supports the following time unit qualifiers:
420+ - U: Microseconds
421+ - T: Milliseconds
422+ - s: Seconds
423+ - m: Minutes
424+ - h: Hours
425+ - d: Days
426+ - w: Weeks
427+
428+ For example, '100U' is 100 microseconds, '50T' is 50 milliseconds, '2s' is 2 seconds, '30m' is 30 minutes,
429+ '1h' is 1 hour, '7d' is 7 days, and '2w' is 2 weeks. Please note that months (M) and years (Y) are not supported as
430+ units for the ` TOLERANCE ` clause.
431+
432+ See [ ` ASOF JOIN documentation ` ] ( /docs/reference/sql/asof-join#tolerance-clause ) for more examples with the ` TOLERANCE ` clause.
433+
398434## SPLICE JOIN
399435
400436` SPLICE JOIN ` is a full ` ASOF JOIN ` . It will return all the records from both
0 commit comments