Subject SV: [firebird-support] Problem with simple query result - where is problem?
Author Svein Erling Tysvær
Is there any chance that there could be two or more rows in OSTE2 (one with null or 0 and one with 1) that somehow links to the same A2?

Try the following query to see if this is the case:

SELECT A2.ID, OSTE2.FLAGA_TEST, OSTE3.FLAGA_TEST
FROM OBIEKTST_EX OSTE2
JOIN OBIEKTST_DB OST2 ON OST2.ID=OSTE2.ID_OBIEKTST
JOIN ADRESY_DB A2 ON A2.ID=OST2.ID_OBJ
JOIN ADRESY_DB A3 ON A2.ID=A3.ID AND A2.STAN=A3.STAN
JOIN OBIEKTST_DB OST3 ON A3.ID=OST3.ID_OBJ AND OST2.SYSTEM=OST3.SYSTEM
JOIN OBIEKTST_EX OSTE3 ON OST3.ID=OSTE3.ID_OBIEKTST
WHERE A2.STAN='Aktywny'
AND OST2.SYSTEM='R0'
AND (OSTE2.FLAGA_TEST IS NULL OR OSTE2.FLAGA_TEST=1)
AND OSTE3.FLAGA_TEST=0

If my head works sufficiently (not quite well today), this should give you the rows that make the difference between 207 and 210.

HTH,
Set