{"id":"1594fbd9539b4ea6","repo":"drizzle-team/drizzle-orm","slug":"no-fields-selected-for-table-tableconfig-tsname-1594fb","errorCode":null,"errorMessage":"No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")","messagePattern":"No fields selected for table \"(.+?)\" \\(\"(.+?)\"\\)","errorType":"exception","errorClass":"DrizzleError","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/mysql-core/dialect.ts","lineNumber":884,"sourceCode":"\t\t\t\t\ton: sql`true`,\n\t\t\t\t\ttable: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),\n\t\t\t\t\talias: relationTableAlias,\n\t\t\t\t\tjoinType: 'left',\n\t\t\t\t\tlateral: true,\n\t\t\t\t});\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage: `No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")`,\n\t\t\t});\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`json_array(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field, tsKey, isJson }) =>\n\t\t\t\t\t\tisJson\n\t\t\t\t\t\t\t? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),","sourceCodeStart":866,"sourceCodeEnd":902,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/mysql-core/dialect.ts#L866-L902","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndb.query.users.findFirst({\n  columns: { id: false, name: false, email: false }, // all excluded => empty\n});\n\n// after - omit columns to select all, or include at least one\ndb.query.users.findFirst({ columns: { id: true } });\n// or\ndb.query.users.findFirst({}); // selects all columns","handlingStrategy":"validation","validationCode":"function hasAtLeastOneField(cfg: { columns?: Record<string, boolean>; with?: object; extras?: object }): boolean {\n  const colValues = cfg.columns ? Object.values(cfg.columns) : [];\n  const anyIncluded = cfg.columns == null || colValues.some(Boolean) || colValues.some((v) => v === false && !colValues.every((x) => x === false));\n  return cfg.columns == null || colValues.includes(true) || (colValues.some((v) => v === false) && !colValues.every((v) => v === false)) || Boolean(cfg.with) || Boolean(cfg.extras);\n}","typeGuard":"function querySelectsAnything(cfg: { columns?: Record<string, boolean>; with?: object; extras?: object }): boolean {\n  if (!cfg.columns) return true; // selects all\n  const vals = Object.values(cfg.columns);\n  if (vals.every((v) => v === false)) return Boolean(cfg.with) || Boolean(cfg.extras);\n  return true;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["mysql","rqb","relational","select","config"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}