drizzle-team/drizzle-orm · error · DrizzleError
No fields selected for table "${tableConfig.tsName}" ("${tab
Error message
No fields selected for table "${tableConfig.tsName}" ("${tableAlias}") What it means
Thrown by MySqlDialect.buildRelationalQuery (line 884, lateral variant) when the computed selection for a nested relational query is empty. Reached via the RQB API (db.query.table.findMany/findFirst) when the combination of columns/with/extras yields nothing to select.
Source
Thrown at drizzle-orm/src/mysql-core/dialect.ts:884
on: sql`true`,
table: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),
alias: relationTableAlias,
joinType: 'left',
lateral: true,
});
selection.push({
dbKey: selectedRelationTsKey,
tsKey: selectedRelationTsKey,
field,
relationTableTsKey: relationTableTsName,
isJson: true,
selection: builtRelation.selection,
});
}
}
if (selection.length === 0) {
throw new DrizzleError({
message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`,
});
}
let result;
where = and(joinOn, where);
if (nestedQueryRelation) {
let field = sql`json_array(${
sql.join(
selection.map(({ field, tsKey, isJson }) =>
isJson
? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`
: is(field, SQL.Aliased)
? field.sql
: field
),View on GitHub (pinned to b7862528fd)
Solutions
- Set columns to undefined/omit it to select all columns, or ensure at least one column is true (include) or not all are false (exclude).
- Add at least one `with` relation or one `extras` entry if you genuinely want a minimal selection.
- If using a dynamic columns object, validate that at least one field is selected before calling the query.
Example fix
// before
db.query.users.findFirst({
columns: { id: false, name: false, email: false }, // all excluded => empty
});
// after - omit columns to select all, or include at least one
db.query.users.findFirst({ columns: { id: true } });
// or
db.query.users.findFirst({}); // selects all columns Defensive patterns
Strategy: validation
Validate before calling
function hasAtLeastOneField(cfg: { columns?: Record<string, boolean>; with?: object; extras?: object }): boolean {
const colValues = cfg.columns ? Object.values(cfg.columns) : [];
const anyIncluded = cfg.columns == null || colValues.some(Boolean) || colValues.some((v) => v === false && !colValues.every((x) => x === false));
return cfg.columns == null || colValues.includes(true) || (colValues.some((v) => v === false) && !colValues.every((v) => v === false)) || Boolean(cfg.with) || Boolean(cfg.extras);
} Type guard
function querySelectsAnything(cfg: { columns?: Record<string, boolean>; with?: object; extras?: object }): boolean {
if (!cfg.columns) return true; // selects all
const vals = Object.values(cfg.columns);
if (vals.every((v) => v === false)) return Boolean(cfg.with) || Boolean(cfg.extras);
return true;
} Prevention
- Don't set every column to false in the RQB columns config.
- Omit `columns` to select all columns.
- Add a `with` relation or `extras` if you want a minimal selection.
- Validate dynamic columns objects before calling findFirst/findMany.
When it happens
Trigger: Using db.query.X.findFirst({ columns: { ... } }) where every column is set to false (exclude mode) and there are no `with` relations and no `extras`. After filtering, selectedColumns is empty and no relations/extras are added, so selection.length === 0.
Common situations: Misunderstanding the columns config as include-only and setting all to false; programmatically building a columns object that resolves to all-false; querying a relation but the relation config produced no fields.
Related errors
- No fields selected for table "${tableConfig.tsName}" ("${tab
- Your "${f.path.join('->')}" field references a column "${tab
- Alias "${tableName}" is already used in this query
- Set operator error (union / intersect / except): selected fi
- Cannot execute a query on a query builder. Please use a data
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/1594fbd9539b4ea6.json.
Report an issue: GitHub.