You can translate the question and the replies:

Select Distinct records based on a particular value in another column

I have a result of employees with "employee id" that has duplicates. I have another column called "leader level" i want to keep unique records of the employee id that has the lowest value of leader level (i.e. if the same employee id is in row 1 and 2 and row 1 has a leader value of 5 and row 2 has a leader value of 1 I should only keep row 2). can this be accomplished by doing and SELECT DISTINCT and an ORDER BY for the leader level column? * one other point. In this example I want to distinct by "employee id" after the sort but I want to keep another column that is not unique called "id". Is there away to remove the duplicates only for a certain field but keep the values for another that might have a different value in the rows?
user
05-10-2020 09:50:07 -0400
code

1 Answer

Hi, The Distinct clause will always consider all the columns of the view unless specific columns are specified in query. You could try different options to accomplish this. * You could use analytical functions like [Row_number](https://community.denodo.com/docs/html/browse/latest/vdp/vql/appendix/syntax_of_condition_functions/analytic_functions_window_functions#row-number) to handle the duplicate values and order the result based on the another column. You could do it in the underlying data source or in Denodo platform either way the data source has to support the analytical function. * Write a query in Denodo platform to handle the duplicates and use that to create a view. See below sample query. ``` SELECT b.field_B FROM view_B AS b INNER JOIN (SELECT field_B, min(field_A) AS field_A FROM view_B GROUP BY field_B) AS a ON (b.field_B = a.field_B AND b.field_A = a.field_A) ``` You can take a look at [Defining a Derived view](https://community.denodo.com/docs/html/browse/latest/vdp/vql/defining_a_derived_view/defining_a_derived_view) to check the syntax and details for creating a view. For storing multiple row values in a single row check if[ Pivoting the data](https://community.denodo.com/kb/view/document/How%20to%20Pivot%20and%20Unpivot%20views?category=Combining+Data) can help you. If the underlying data source supports Pivoting you could do that in the data source itself and create views on top of that output. If you would like to store the data (after pivot) in a array like structure take a look at [Compound Types](https://community.denodo.com/docs/html/browse/latest/vdp/vql/advanced_characteristics/management_of_compound_values/management_of_compound_values) in Virtual DataPort. Hope this helps!
Denodo Team
 Edited on: 08-10-2020 02:08:15 -0400
code
You must sign in to add an answer. If you do not have an account, you can register here