Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to avoid duplicated record be loaded

Hello,

I have problem with duplicated record need to be avoid during the loading. Below is the table source. When I load it into Qlikview, I want the first row of the duplicated record by key word to be loaded. So the result should be the table A at right. Please help.

error loading image

1 Solution

Accepted Solutions
Not applicable
Author

Thanks John,

If the Dispute ID is put in order, your approach works. I have used minstring() and it works right now. Thanks again your help.

View solution in original post

13 Replies
Anonymous
Not applicable
Author

Try an inline query like below:

select dispute_id, id

from table_source a

where id = (select min(id)

from table_source b

where a.dispute_id = b.dispute_id)

Regards,

Dinesh.

vgutkovsky
Master II
Master II

This is the QV way of getting it to work:

data:
LOAD
*
FROM datasource.qvd (qvd);

finanl_data:
NOCONCATENATE LOAD
*
RESIDENT data
WHERE NOT exists([Dispute ID],[Dispute ID])
ORDER BY [Dispute ID],ID
;

DROP TABLE data;

Regards,

Not applicable
Author

Thanks Vlad,

There is no record loaded in finanl_data table.

vgutkovsky
Master II
Master II

Oops, I misused the exists() function. It would actually be easier to do this whole thing with a group by:

data:
LOAD
*
FROM datasource.qvd (qvd);

final_data:
NOCONCATENATE LOAD
[Dispute ID],
firstsortedvalue(ID,ID) as ID
RESIDENT data
GROUP BY [Dispute ID]
;

DROP TABLE data;

johnw
Champion III
Champion III

I bet you could do it in one step for performance and simplicity:

LOAD
"Dispute ID"
,"ID"
FROM datasource.qvd (QVD)
WHERE not exists("Dispute ID")
;

The first time you encounter a dispute ID, it won't exist (in QlikView), so it would be loaded. Any other time you encounter that same dispute ID, it WILL exist, so should be skipped. And I think this would be an optimized QVD load.

However, this method counts on the data being written to your QVD in the correct order. If you can't guarantee that, you wouldn't want to do what I'm showing, because you'd get a "random" ID associated with the dispute ID.

Not applicable
Author

It is eliminated duplicated [Dispute ID] but there is no value in ID field.

johnw
Champion III
Champion III

My approach works as posted. Vlad's works if you replace firstsortedvalue(ID,ID) with minstring(ID). I'm not sure why firstsortedvalue(ID,ID) isn't working, though. See attached.

Edit: Ah, looked it up. Firstsortedvalue() doesn't work because it requires the sort sequence to be numeric, not alphanumeric. How rude!

Not applicable
Author

John,

Your approach doesn't work on QV10. Check this http://community.qlik.com/forums/t/39497.aspx.

vgutkovsky
Master II
Master II

Interesting, thanks for the insight John!