DB2 SELECT EXCEPT with WHERE clause

倖福魔咒の 提交于 2019-12-23 02:36:43

问题


I'm trying to compare two tables in a DB2 database in z/OS using SPUFI to submit SQL queries.

I'm doing this by using EXCEPT to see the difference between two SELECT queries.

I need to filter the SELECT statement from the first query with a WHERE clause.

SELECT KEY_FIELD_1,LOOKUP_FIELD_1  
FROM TABLE_1  
WHERE FILTER_FIELD = '1'  
EXCEPT  
SELECT KEY FIELD_2,LOOKUP_FIELD_2  
FROM TABLE_2

I got results back, but it also returned an error -199 Is this because the WHERE clause is not present in the second SELECT statement?

ERROR: ILLEGAL USE OF KEYWORD EXCEPT.  
TOKEN <ERR_STMT> <WNG_STMT> GET SQL  
SAVEPOINT HOLD FREE ASSOCIATE WAS EXPECTED

回答1:


Try introducing parentheses e.g.

( SELECT KEY_FIELD_1,LOOKUP_FIELD_1  
FROM TABLE_1  
WHERE FILTER_FIELD = '1' )  
EXCEPT  
( SELECT KEY FIELD_2,LOOKUP_FIELD_2  
FROM TABLE_2 )


来源:https://stackoverflow.com/questions/40680708/db2-select-except-with-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!