0

I have a list of contracts like this query:

select 
    r.vnum, r.BEITRAGSGR 
from 
    ufrisk r 
inner join 
    ufvert v on r.vnum = v.vnum 
inner join 
    allgvert a on a.vnum = r.vnum 
where 
    a.version = r.version

How can I search for all contracts that have more than one (different) value in the column r.BEITRAGSGR?

Example Query result

1 Answer 1

1

Assuming vnum is a "contract", you can use aggregation:

select vnum
from ufrisk
group by vnum
having min(BEITRAGSGR) <> max(BEITRAGSGR);

If you want the original rows, use exists:

select u.*
from ufrisk u
where exists (select 1
              from ufrisk u2
              where u2.vnum = u.vnum and u2.BEITRAGSGR <> u.BEITRAGSGR
             );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.