I have two rows from a table that has many columns. How do I return only those columns where the value for row1 does not equal the value for row2?
I’m using Oracle 11.1.0.07
~~ Edit: clarification ~~
Example:
So I’ve got a table with rows:
1 a b c d e f g h i j k l
2 a x c d e x g h y j k l
3 a b x d e x g h x y k z
I want to return rows where id (first column) is 1 or 3, only those columns that are different. So:
1 c f i j l
3 x x x y z
with column names.
In reality, the table I’m pulling from has 223007 rows, and 40 columns. The above is a simplified example. There are two rows (one each for primary key values) that I’m wanting to compare.
First, the SQL language was not designed for dynamic column generation. For that, you need to write dynamic SQL which should be done in a middle-tier or reporting component.
Second, if what you seek is to compare two specific rows, then the simplest solution would probably be to return those rows and analyze them in a middle-tier component. However, if you accept that we must return all columns and you insist on doing this in SQL, this is one solution:
Results: