Documentation

JOIN clause

Use the JOIN clause to join data from different tables together based on logical relationships.

Syntax

SELECT_clause
FROM <left_join_items>
[INNER | LEFT [OUTER] | RIGHT [OUTER] | FULL [OUTER]] JOIN <right_join_items>
ON <join_condition>
[WHERE_clause]
[GROUP_BY_clause]
[HAVING_clause]
[ORDER_BY_clause]
  • Copy
  • Fill window

Arguments

  • left_join_items: One or more tables specified in the FROM clause that represent the left side of the join.
  • right_join_items: One or more tables specified in the JOIN clause that represent the right side of the join.
  • join_condition: A predicate expression in the ON clause that uses the = (equal to) comparison operator to compare column values from the left side of the join to column values on the right side of the join. Rows with values that match the defined predicate are joined using the specified join type.

If both sides of the join include columns with the same name, you need to use the fully-qualified reference to prevent ambiguity. A fully-qualified reference uses dot notation to reference both the table name and the column name–for example: table_name.column_name

Join types

The following joins types are supported:

Join sample tables

The examples below illustrate join methods using the following tables:

prod_line
timestationproduced
2025-03-25T08:00:00ZB126
2025-03-25T09:00:00ZB154
2025-03-25T10:00:00ZB156
2025-03-25T11:00:00ZB1
2025-03-25T12:00:00ZB182
errors
timestationlevelmessage
2025-03-25T10:00:00ZB1warnMaintenance required
2025-03-25T11:00:00ZB1critStation offline

INNER JOIN

Inner joins combine rows from tables on the left and right side of the join based on common column values defined in the ON clause. Rows that don’t have matching column values are not included in the output table.

Inner join example

SELECT
  *
FROM
  prod_line
RIGHT JOIN errors ON
  prod_line.time = errors.time
  AND prod_line.station = errors.station
ORDER BY
  prod_line.time
  • Copy
  • Fill window
Inner join results
timestationproducedtimestationlevelmessage
2025-03-25T10:00:00ZB1562025-03-25T10:00:00ZB1warnMaintenance required
2025-03-25T11:00:00ZB12025-03-25T11:00:00ZB1critStation offline

LEFT [OUTER] JOIN

A left outer join returns all rows from the left side of the join and only returns data from the right side of the join in rows with matching column values defined in the ON clause.

Left outer join example

SELECT
  *
FROM
  prod_line
LEFT JOIN errors ON
  prod_line.time = errors.time
  AND prod_line.station = errors.station
ORDER BY
  prod_line.time
  • Copy
  • Fill window
Left outer join results
timestationproducedtimestationlevelmessage
2025-03-25T08:00:00ZB126
2025-03-25T09:00:00ZB154
2025-03-25T10:00:00ZB1562025-03-25T10:00:00ZB1warnMaintenance required
2025-03-25T11:00:00ZB12025-03-25T11:00:00ZB1critStation offline
2025-03-25T12:00:00ZB182

RIGHT [OUTER] JOIN

A right outer join returns all rows from the right side of the join and only returns data from the left side of the join in rows with matching column values defined in the ON clause.

Right outer join example

SELECT
  *
FROM
  prod_line
RIGHT JOIN errors ON
  prod_line.time = errors.time
  AND prod_line.station = errors.station
ORDER BY
  prod_line.time
  • Copy
  • Fill window
Right outer join results
timestationproducedtimestationlevelmessage
2025-03-25T10:00:00ZB1562025-03-25T10:00:00ZB1warnMaintenance required
2025-03-25T11:00:00ZB12025-03-25T11:00:00ZB1critStation offline

FULL [OUTER] JOIN

A full outer join returns all data from the left and right sides of the join and combines rows with matching column values defined in the ON clause. Data that is not available on each respective side of the join is NULL.

Full outer join example

SELECT
  *
FROM
  prod_line
FULL JOIN errors ON
  prod_line.time = errors.time
  AND prod_line.station = errors.station
ORDER BY
  time
  • Copy
  • Fill window
Full outer join results
timestationproducedtimestationlevelmessage
2025-03-25T08:00:00ZB126
2025-03-25T09:00:00ZB154
2025-03-25T10:00:00ZB1562025-03-25T10:00:00ZB1warnMaintenance required
2025-03-25T11:00:00ZB12025-03-25T11:00:00ZB1critStation offline
2025-03-25T12:00:00ZB182

Troubleshoot joins

Ambiguous reference to unqualified field

If a column exists on both sides of the join and is used in the SELECT, ON, WHERE, HAVING, GROUP BY, or ORDER BY clause, you must use a fully-qualified reference. For example, if both sides of the join have a time column and you want to explicitly select a time column, you must specifiy which side of the join to use the time column from:

SELECT
  prod_line.time,
  produced,
  message,
FROM
  prod_line
INNER JOIN errors ON
  -- ...
  • Copy
  • Fill window

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: