I have a DB2 table with "union" as the column name. How do I select this column on a select statement when it is same as a SQL keyword? I tried using select [union] from table but it didn't work.
I have a DB2 table with "union" as the column name. How do I select this column on a select statement when it is same as a SQL keyword? I tried using select [union] from table but it didn't work.
@user2914171 answered correctly in the comments.
SELECT "UNION" FROM TABLE
not
SELECT "union" FROM TABLE
Note that "UNION" must be upper case, or more correctly, the case specified in SYSCOLUMNS, but as long as the create table did not use quotes, or the table was defined using DDS, DB2 for i defaults to all upper case.
You can find the true case of the field name by:
select column_name
from qsys2.syscolumns
where table_name = 'TABLE'
and table_schema = 'LIBRARY'