should be a simple resolution but I'm not familiar enough...
I have the following [simplified] query which generates duplicate rows that I need to get rid of.
SELECT MY_ID, DESCRIPTION, NAME
FROM MYTABLE
When I insert the distinct command, DB2 tells me:
SQL0134N Improper use of a string column, host variable, constant, or
function "DESCRIPTION". SQLSTATE=42907
The datatype of DESCRIPTION is LONG VARCHAR and 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.
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 ?
ThanksCan you use:SELECT MY_ID, DESCRIPTION, NAME
FROM MYTABLE
GROUP BY MY_ID, DESCRIPTION, NAME-PatP|||looks like group by doesn't like DESCRIPTION either... same error.
SQL0134N Improper use of a string column, host variable, constant, or
function "DESCRIPTION". SQLSTATE=42907
Showing posts with label familiar. Show all posts
Showing posts with label familiar. Show all posts
Tuesday, March 27, 2012
Sunday, March 25, 2012
DISTINCT query issue
I'm familiar with MySQL and recently started working with MSSQL.
I have a general understanding of how the DISTINCT command works, but would like to expand on that a bit.
I have a general understanding of how the DISTINCT command works, but would like to expand on that a bit.
I need to do a DISTINCT query on a record's 'name' column, but i need all of the values for each of those returned records. So, I need the query to only apply the DISTINCT command to the 'name' column, not the other columns of the received records.
Can someone explain a bit how to word this
Many thanks in advance.
EDIT: Upon reflection, I realize now that this request is counter to the way DISTINCT works. D'oh. Move along, nothing to see here. :(
Hi,
As you have wrote at the end of your message, you can not get such a list.
But if you want to get records of having same specific column value, you can run a select and order by over that column also can add a criteria to filter returned data.
Subscribe to:
Posts (Atom)