Here is the problem: I have two columns in a table that, for each grouping, should have the same order. I want to check that this is true for the existing data before I make that assumption going forward.
Some example 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 would be identical, and ordered identically to
select * from table t where t.gid = 1 order by c2.
The results would also match for gid = 2.
However, if I were to do the same with gid = 3, the order would no longer match. because, in that case, ordering by c2 has a different result from ordering by c1.
I want to check the entire table to insure that ordering by either of these columns will have the same result for each value of gid. Oracle’s MINUS won’t work, as it doesn’t allow order by in the subqueries. My first try, which doesn’t work because of the limitations of MINUS, 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 that helps with the answer.
You might find difference in order in the same record by assigning row_number.