DB Sorter - Sort First X Columns

I have a workflow that ultimately compares two tables. To do this, I sort the PK columns for each table so that the data aligns correctly. Doing a sort on a single table is not a big deal but if I want to do this for a lot of tables, it is a bit of a pain to manually choose columns from the node and then do that again on the other sort node. Most of my tables would be fine with just sorting the first 5 columns of each table (PK fields are always first set of columns). Not always the case but would be easier to just sort first 5 columns unless I override it. Is there a way to do that?

Hi @JLamka , I don’t have Knime in front of me at the moment, and I don’t usually use the DB nodes apart from the DB Query/Query Reader in order to comment about the DB Sorter node, but you can apply the sort via your queries when you are reading instead of using the DB Sorter, and if you want to sort by the first 5 columns, you can add ORDER BY 1, 2, 3, 4, 5 at the end of your query.

ORDER BY 1 in a query refers to the the first column of the SELECT statement, 2 being the second column, 3 being the third, etc

1 Like

@JLamka you could configure the sort node to use flow variables and extract the column headers from each of your tables you want to sort and feed them to the sorter.

I assume the first 5 columns do not always have the same name because then you might just use a component and reuse that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.