Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3942710
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:41:44+00:00 2026-05-20T00:41:44+00:00

I have two rows from a table that has many columns. How do I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:41:44+00:00Added an answer on May 20, 2026 at 12:41 am

    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:

    With Inputs As
        (
        Select 1 As Col1,'a' As Col2,'b' As Col3,'c' As Col4,'d' As Col5,'e' As Col6,'f' As Col7,'g' As Col8,'h' As Col9,'i' As Col10,'j' As Col11,'k' As Col12,'l' As Col13
        Union All Select 2,'a','x','c','d','e','x','g','h','y','j','k','l'
        Union All Select 3,'a','b','x','d','e','x','g','h','x','y','k','z'
        )
        , TransposedInputs As
        (
        Select Col1, 2 As ColNum, Col2 As Value From Inputs
        Union All Select Col1, 3, Col3 From Inputs
        Union All Select Col1, 4, Col4 From Inputs
        Union All Select Col1, 5, Col5 From Inputs
        Union All Select Col1, 6, Col6 From Inputs
        Union All Select Col1, 7, Col7 From Inputs
        Union All Select Col1, 8, Col8 From Inputs
        Union All Select Col1, 9, Col9 From Inputs
        Union All Select Col1, 10, Col10 From Inputs
        Union All Select Col1, 11, Col11 From Inputs
        Union All Select Col1, 12, Col12 From Inputs
        Union All Select Col1, 13, Col13 From Inputs
        )
        , UniqueValues As
        (
        Select Min(Col1) As Col1, ColNum, Value
        From TransposedInputs
        Where Col1 In(1,3)
        Group By ColNum, Value
        Having Count(*) = 1
        )
    Select Col1
        , Min( Case When ColNum = 2 Then Value End ) As Col2
        , Min( Case When ColNum = 3 Then Value End ) As Col3
        , Min( Case When ColNum = 4 Then Value End ) As Col4
        , Min( Case When ColNum = 5 Then Value End ) As Col5
        , Min( Case When ColNum = 6 Then Value End ) As Col6
        , Min( Case When ColNum = 7 Then Value End ) As Col7
        , Min( Case When ColNum = 8 Then Value End ) As Col8
        , Min( Case When ColNum = 9 Then Value End ) As Col9
        , Min( Case When ColNum = 10 Then Value End ) As Col10
        , Min( Case When ColNum = 11 Then Value End ) As Col11
        , Min( Case When ColNum = 12 Then Value End ) As Col12
        , Min( Case When ColNum = 13 Then Value End ) As Col13
    From UniqueValues
    Group By Col1
    

    Results:

    Col1 | Col2      | Col3      | Col4  | Col5      | Col6      | Col7  | Col8      | Col9      | Col10 | Col11 | Col12     | Col13
    1   |   NULL    |   NULL    |   c   |   NULL    |   NULL    |   f   |   NULL    |   NULL    |   i   |   j   |   NULL    |   l
    3   |   NULL    |   NULL    |   x   |   NULL    |   NULL    |   x   |   NULL    |   NULL    |   x   |   y   |   NULL    |   z
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large table (~1M rows now, soon ~10M) that has two ranked
I have two identical tables and need to copy rows from table to another.
I have two functions to add and remove table rows that contain a form
I have two tables: a 'userlist' that has a 'grade' and 'userID' columns, and
Problem: a table of coordinate lat/lngs. Two rows can potentially have the same coordinate.
In MySql, I have two tables, A and B. A has as columns A.id,
I have many rows in a mysql table. There is an order_id column. I
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two applications written in Java that communicate with each other using XML
I have two tables. Widgets, which has information about each widget (Color, size, etc);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.