Informix Error -317
-317 The statement failed becuase you must have the same number of selected
columns in each UNION, INTERSECT, or MINUS query.All rows that are produced in a union, intersect or minus must have the same format, so each SELECT statement in the union, intersect or minus must select the same number of columns. In this union, intersect or minus, one of the second or subsequent SELECT statements does not list the same number of columns as the preceding one. Review the entire union, intersect or minus, and check that all select lists are alike in number and data type. If no appropriate column exists for one of the statements, specify a literal value of the appropriate type at that position. For example, where you need to match a numeric column, specify a literal zero.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-317 is the column-count counterpart of -308: every SELECT statement combined with UNION,
INTERSECT, or MINUS must select the same number of columns, since the combined result has to
present a single consistent row format regardless of which branch a given row came from.
- A
SELECTstatement in the combined query with a different number of columns than the others — the direct, most common cause. - A column added to or removed from one branch's select list (during maintenance) without updating the other branches to match.
- A
SELECT *branch combined with an explicit column list branch, where the underlying table's actual column count doesn't match the explicit list's length. - A branch intentionally omitting a column that doesn't apply to that part of the combined query, without substituting a placeholder value to keep the column counts aligned.
Solutions / Resolution
- Review every
SELECTstatement's column list, per the official guidance, and confirm each selects the same number of columns as the others. - Where a genuinely appropriate column doesn't exist in one branch, substitute a literal value of the matching type to keep column counts (and types) aligned, rather than omitting the column entirely.
- Avoid mixing
SELECT *with explicit column lists across branches of the same combined query — make every branch's column list explicit so mismatches are easy to spot.
Examples
Mismatched column counts
SELECT customer_id, name FROM current_customers
UNION
SELECT customer_id, name, signup_date FROM archived_customers;
-- -317: three columns vs. two
Fix — align the column counts, using a placeholder where a column doesn't apply:
SELECT customer_id, name, NULL AS signup_date FROM current_customers
UNION
SELECT customer_id, name, signup_date FROM archived_customers;
Avoiding SELECT * to keep counts explicit
-- Risky: SELECT * column count depends on the table's current
-- schema, which can drift over time
SELECT * FROM current_orders
UNION
SELECT order_id, customer_id, total, NULL FROM archived_orders;
-- Safer: make every branch explicit
SELECT order_id, customer_id, total FROM current_orders
UNION
SELECT order_id, customer_id, total FROM archived_orders;
Diagnostic Checks
- Count the columns in each
SELECTstatement's list across every branch of theUNION/INTERSECT/MINUS, and confirm they match. - Check for
SELECT *usage in any branch, since its effective column count depends on the table's current schema rather than being visible in the statement text.
Related Errors / Related Topics
- -308 — "The statement failed because corresponding column data types must be compatible for each UNION, INTERSECT, or MINUS query." The closest sibling — the type-compatibility counterpart of this column-count restriction; both apply to the same class of combined queries.
Every branch of a UNION/INTERSECT/MINUS needs an identical column count — use explicit
column lists (never SELECT *) and literal placeholders where a real column doesn't apply.