diff --git a/src/libknot/rrset.c b/src/libknot/rrset.c
index cc3f3981cc86bde066728ada82752f8a19c0f4cb..856e7ed6ac321672c277a6cd9585819c6d2c52bc 100644
--- a/src/libknot/rrset.c
+++ b/src/libknot/rrset.c
@@ -166,7 +166,7 @@ int rrset_rdata_compare_one(const knot_rrset_t *rrset1,
 			int size2 = knot_dname_size(dname2);
 			cmp = memcmp(dname1, dname2,
 			             size1 <= size2 ? size1 : size2);
-			if (cmp == 0 && size1 == size2) {
+			if (cmp == 0 && size1 != size2) {
 				cmp = size1 < size2 ? -1 : 1;
 			}
 			offset += knot_dname_size(dname1);