Duplicates in tree

I have the following data set in a database:

UID ID Label Version ParentID
1 10 Text 1 1 11
2 11 Text 2 1 0
3 12 Text 3 1 0
4 10 Text 1 2 11
5 10 Text 1 3 11

Basically I have one item with the same ID and with multiple version.

How can i only show the latest version in the tree? So only the following data:

UID ID Label Version ParentID
2 11 Text 2 1 0
3 12 Text 3 1 0
5 10 Text 1 3 11

I currently show the tree items “text 1” but also multiplies the number of childs under these items. See attach where “Salarisadminstratie” is “text 1”

Tree displayes all data that are loaded in it. Therefore, you should filter tree items before they are loaded in tree. Item ids should be unique.

How can i filter this data?
Using a group by function does not work form me.

Sorry, my previous answer was not specific enough. Data should be filtered before they are loaded in tree. For example, it can be done in server-side script that generates xml or json with tree items.

add a column to the table , defaule value 1

trans begin
update talbe … set UID = 0 where UID = 1
insert table …

trans end

select …from table where UID = 1

duplicates date must unique before load to tree

add a column col to the table , defaule value 1

the best way is writing a storage procudure with transaction in database

trans begin
update talbe … set col = 0 where ID = 10 and col = 1
insert table …

trans end

select …from table where col = 1

duplicates data must unique before loading to tree