Here is the problem: I have two columns in the table that should be in the same order for each group. I want to verify that this is true for existing data before I make this assumption in the future.
Some sample data:
gid c1 c2 1 1 5 1 2 7 2 1 22 2 2 38 2 3 40 3 1 4 3 2 8 3 3 2
As you can see, if I were to use select * from table t where t.gid = 1 order by c1
the result will be identical and ordered in exactly the same way as select * from table t where t.gid = 1 order by c2
.
The results will also match gid = 2. However, if I did the same with gid = 3, the order would no longer match. because in this case the order of c2
has a different result from ordering on c1
.
I want to check the entire table to ensure that ordering by any of these columns will have the same result for each gid
value. Oracle MINUS
will not work because it does not allow order by
in subqueries. My first attempt, which does not work due to MINUS
restrictions, was:
select gid, c1, c2 from table order by gid, c1, c2 minus select gid, c1, c2 from table order by gid, c2, c1;
I am using oracle 11g if this helps with the answer.
source share