<a id="lightning-tables-sql-reference"></a>

# SQL Reference for Lightning Table Queries in Confluent Cloud

A Lightning Table query runs read-only SQL on a single Lightning
Table. This SQL applies whether you query in the Confluent Cloud Console,
through an HTTP API, or with a Model Context Protocol (MCP) client.

#### IMPORTANT
Lightning Tables are rolling out to Confluent Cloud accounts in phases. If
you don’t see this feature, it’s not available for your account at
this time.

<a id="lightning-tables-supported-sql"></a>

## Supported SQL capabilities

A Lightning Table query supports the following SQL capabilities:

- **Key lookups**: Look up rows by primary key value.
- **Filters**: Narrow results in the `WHERE` clause by using the
  following operators: equality (`=`), inequality (`!=`),
  comparison (`>`, `<`, `>=`, `<=`), set membership (`IN`,
  `NOT IN`), null checks (`IS NULL`, `IS NOT NULL`), pattern
  matching (`LIKE`, `NOT LIKE`), and range (`BETWEEN`).
- **Compound predicates**: Combine multiple conditions with the `AND`
  and `OR` operators.
- **Column selection**: Select specific columns to reduce the response
  size, or select all columns.
- **Ordering**: Sort results in ascending or descending order with the
  `ORDER BY` clause.
- **Row limits**: Control the number of rows returned with the
  `LIMIT` clause.

### Example query

The following query reads the Lightning Table for the `orders` topic.
It returns the 10 most recent orders with more than five units.

```sql
SELECT ORDERID, ITEMID, ORDERUNITS
FROM `orders`
WHERE ORDERUNITS > 5
ORDER BY ORDERTIME DESC
LIMIT 10;
```

The query uses the following supported capabilities:

- **Column selection**: The `SELECT` clause returns only the
  `ORDERID`, `ITEMID`, and `ORDERUNITS` columns.
- **Filters**: The `WHERE` clause uses the `>` operator to return
  only orders with more than five units.
- **Ordering**: The `ORDER BY` clause sorts the orders by the
  `ORDERTIME` column, newest first.
- **Row limits**: The `LIMIT` clause returns at most 10 rows.

### Topic names

If a topic name contains any character other than letters and numbers,
enclose it in backticks, as in the statement
`SELECT * FROM `web-orders` LIMIT 10;`.
Quoted names are case sensitive, but unquoted names aren’t.

### Limits

Limits, such as the maximum number of rows a query returns, depend on
the query interface. For the limits that apply when you query with MCP,
see [Query limits](../../ai/real-time-context-engine/query-data.md#rtce-query-limits).

## Unsupported queries

A Lightning Table query is read-only. It doesn’t support the following
operations:

- Aggregate functions (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`)
- `GROUP BY` clauses
- Joins
- Subqueries
- Set operators (`UNION`, `EXCEPT`, `INTERSECT`)
- DDL statements (`CREATE`, `ALTER`, `DROP`)
- DML statements (`INSERT`, `UPDATE`, `DELETE`)

Confluent Cloud rejects an unsupported query without running it.

## Related content

- [Lightning Table Queries in Confluent Cloud](overview.md#lightning-tables-query-overview)
- [Manage Lightning Tables in Confluent Cloud](../manage.md#lightning-tables-manage)
- [Lightning Tables in Confluent Cloud](../overview.md#lightning-tables-overview)

#### NOTE
This website includes content developed at the [Apache Software Foundation](https://www.apache.org/)
under the terms of the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0.html).
