- Aug 28, 2001
- 52,844
- 1,049
- 126
should be a simple resolution but I'm just not getting it...
I have the following [simplified] query which generates duplicate rows that I need to get rid of. I'm mainly concerned with MY_ID being duped... other fields don't matter if they're duped but I still need the other fields there in the result set.
SELECT MY_ID, DESCRIPTION, NAME
FROM MYTABLE
When I insert the distinct command after select:
SELECT DISTINCT MY_ID, DESCRIPTION, NAME
FROM MYTABLE
DB2 errors with:
SQL0134N Improper use of a string column, host variable, constant, or
function "DESCRIPTION". SQLSTATE=42907
The datatype of DESCRIPTION is LONG VARCHAR and again - that cannot change nor the need to query that column. It seems this is preventing distinct from working. It will work without DESCRIPTION being pulled, of course, but again - I need that column.
SELECT DISTINCT(MY_ID), DESCRIPTION, NAME
FROM MYTABLE .... spat out the same error thinking it's still distinct on all.
How do I use SQL to remove the duplicates I am getting since distinct seemingly cannot be used in this scenario ? Can a "WHERE" clause somehow help ?
I have the following [simplified] query which generates duplicate rows that I need to get rid of. I'm mainly concerned with MY_ID being duped... other fields don't matter if they're duped but I still need the other fields there in the result set.
SELECT MY_ID, DESCRIPTION, NAME
FROM MYTABLE
When I insert the distinct command after select:
SELECT DISTINCT MY_ID, DESCRIPTION, NAME
FROM MYTABLE
DB2 errors with:
SQL0134N Improper use of a string column, host variable, constant, or
function "DESCRIPTION". SQLSTATE=42907
The datatype of DESCRIPTION is LONG VARCHAR and again - that cannot change nor the need to query that column. It seems this is preventing distinct from working. It will work without DESCRIPTION being pulled, of course, but again - I need that column.
SELECT DISTINCT(MY_ID), DESCRIPTION, NAME
FROM MYTABLE .... spat out the same error thinking it's still distinct on all.
How do I use SQL to remove the duplicates I am getting since distinct seemingly cannot be used in this scenario ? Can a "WHERE" clause somehow help ?
