Return only the columns with different values.

Hi all

I am trying to solve a seemingly trivial problem but can't seem to get any clear answer anywhere in any forum. Consider a single table with 5 columns and only two lines:
row_id           first_name         last_name        age            gender
1                    John                  doe               27             M
1                    Jane                  doe               27              F  
Assume that there is no primary key or any other constraint. Also assume that there are only and only two lines of this table. So I need basically a query that, overall above lines, would return first name and sex, because they are only different columns in two lines, as well as their values. Even if I can get sort of column names that are different and that would be enough that I can easily access the values later. It is also important to remember that I may not know the names of the columns in the columns, so basically, somehow, I use user_tab_columns in the process.

Any help appreciated.

Published by: 894302 on May 1, 2013 10:35

Hello

894302 wrote:
The exact release could be just a varchar variable that lists all the columns that have different values with each column name separated by commas. We'll call the query you want as a QUERY. So, if I do something like

Select the REQUEST of double; Output should be: 'first_name, equality of the sexes. Is this possible?

In this case:

SELECT     RTRIM ( DECODE (a.row_id,     b.row_id,     NULL, 'row_id,')     ||
                DECODE (a.first_name, b.first_name, NULL, 'first_name,') ||
          DECODE (a.last_name,  b.last_name,  NULL, 'last_name,')  ||
          DECODE (a.age,        b.age,          NULL, 'age,')      ||
          DECODE (a.gender,     b.gender,     NULL, 'gender,')
           , ','
           )          AS different_columns
FROM     rhit_table_x  a
JOIN     rhit_table_x  b  ON  a.ROWID     < b.ROWID
;

Output:

DIFFERENT_COLUMNS
---------------------------------------
first_name,gender

This assumes that you have really a table, then you can use ROWID to distinguish the lines, since there is no primary key.
If this isn't the case, you first assign ROW_NUMBER in a subquery.

Tags: Database

Similar Questions

  • Return only the records with a string of text that is less than a certain value?

    Hi people,

    I'm not sure whether this is possible or not, but worth-

    I need to be able somehow output only the lines with the text of a column field less to (because of the arguments) 30 characters (including spaces). I know that I can use CFs Left() function to cut the chain, but I don't want to have words cut off mid-sentence. Therefore, I want to somehow restrict the query to only the records that contain a string of less than 30 characters.

    Is this possible?

    Thanks in advance :-)

    You can use the length of the db function. It may or may not be named LEN()

    SELECT SomeColumn
    FROM YourTable
    WHERE LEN (SomeColumn)<=>

    Or you can retrieve all of the records and use one of the functions of the chain at cflib.org as FullLeft().
    http://www.cflib.org/UDF.cfm?id=329

  • not able to see the column with missing values

    Hello world. For a few days, I'm not able to view column that only have missing values in excel using smartview. I checked the deleted column values are all Unflagged, as to remove the missing blocks in the smartview options.
    Maybe there's something else I have installation?

    Thank you

    After unflagging "Delete column" refreshing sheet wasn't enough. To make the active sheet active options must be closed. Options then work correctly in the new worksheet (in the same excel file).

  • LINES in COLUMNS with different values for each column (after division)

    Hello
    I have a table called summary where I produced, month, value,.

    When I used select * tab, I get months jan, Feb, mar, Apr. I wrote a query to get the months(jan,feb,...) columns

    SELECTmax (DECODE(ROWNUM,1,month)) Column1
    + Max (decode(rowNum,2,month)) table Column2 +.

    as this up to 12 months
    After that, I want to get the NEWVALUE for each month.
    I wrote a query to get the value, but I get the value only for the first month, and for the rest, I get NULL values.

    Select max (DECODE(ROWNUM,2,vallue)) Column1, Column2 of max table (DECODE(ROWNUM,3,vallue))



    Is it possible to get the newvalues for each month (in sql only) if so, please help me

    Thank you
    Chand
  • Discover with function as datasource returns only the first line.

    Hello

    I created the following function to get the status of all the rules for the instances of SQL Server.

    The data type of the function output has been configured as 'List of SQLInstanceRuleStatuss', where SQLInstanceRuleStatuss is the custom type, I created in the same module.

    When I tested the function, it returns all instances of SQL Server with two other columns.

    But when I try to create a view with the Rows property that is configured to use the feature, it returns only the first line:

    sqlRules = new ArrayList();

    queryStatement = server. QueryService.createStatement ("(DBSS_Instance)");

    queryResult = server. QueryService.executeStatement (queryStatement);

    for (it in queryResult.topologyObjects)

    {

    sqlRule is functionHelper.createDataObject ("westjet_mark_dev:SQLInstanceRuleStatus", "none", "test");.

    sqlRule.instance = it;

    sqlRule.ruleName = 'test rule name';

    sqlRule.status = false;

    sqlRules.add (sqlRule);

    }

    Return sqlRules;

    Did I miss something?

    Thank you

    Mark

    Mark,

    I think I forgot something

    sqlRule=functionHelper.createDataObject("westjet_mark_dev:SQLInstanceRuleStatus","none","test");

    you create the test id

    change your line of

    sqlRule=functionHelper.createDataObject("westjet_mark_dev:SQLInstanceRuleStatus","none",null);

    This should allow the creation of a single object in your loop for

  • return only the decimal value

    What function can I use to return only the decimal value of a formula

    (97 * 2.2) / 14 value returns 15.24

    I only want to use le.24

    Salvation is

    Use the formula - INT (formula)

    In the special case above:

    =(97*2.2)/14 - INT ((97*2.2)/14)

    You see two places to the right of the decimal separator in reason to be rounded off to the value real, in the shape of the cell to only show as two decimal places, either by setting the width of the cell close enough to force the rounding of the displayed value.

    Note that if the result is rounded (using the ROUND function) the actual value of the cell will be the rounded value. For the other two cases, the value displayed indicates only two decimal places, but the real value in the cell (and the additional calculations used by referring to this cell) is 0.242857142857144, which could lead to surprises in the results of the calculations downstream.

    Kind regards

    Barry

  • I have a column with two values, separated by a space, in each line. How to create 2 new columns with the first value in a column, and the second value in another column?

    I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?

    Add two new columns after than the original with space separated values column.

    Select cell B1 and type (or copy and paste it here) the formula:

    = IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    shortcut for this is:

    B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")

    or

    the formula of the C1 could also be:

    = IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")

    Select cells B1 and C1, copy

    Select cells B1 at the end of the C column, paste

  • Two tables with different values of basic on an analysis filter

    Hi guys,.

    Let assume that I have an analysis with columns: group_id and sales.
    On this basis I would like to create two tables: table1 where group_id = 1 and table2 where group_id = 2.

    OBIEE is able to do?

    Kind regards
    Slavi

    Hi Slavi,

    You can do it in a single analysis, but you have to have the column with group_id twice.

    Bring, group_id_1, group_id_2 (same column), sale

    Now in table 1.

    bring group_id_1, sales

    Then in the selection steps for group_id_1-> select members-> Action choose keep only-> choose the value of the filter 1

    This will filter the table 1 with group_id 1

    In table2 group_id_2 porter, sales

    Then do the same step for group_id_2 with the value 2.

    You now have two reports with different filter in the same report.

    If you want you can keep the same name column for the two columns group_id, I just kept group_id_1, group_id_2 for easy reference.

  • two rows of delete with different values

    Hello

    I wouldn't lines with the same id and have values of E and F 10258932.

    I would like the following data:
    A        B  C      D     E N
    -------- -- ------ ----- - -
    10258927 1  103,35 0
    10258929 3  284,85 89,52 E N
    10258929 4  323,85 89,52 E N
    10258930 5  478,80 91,53 E N
    10258931 6  436,67 78,09 E N
    But I have the following lines:
    SQL> with my_table as
      2  (
      3  select '10258927' a, '1'  b, '103,35'  c, '0'      d,   NULL  e from dual union all    
      4  select '10258928' a, '2'  b, '0'       c, '15,19'  d,  'E'    e from dual union all
      5  select '10258929' a, '3'  b, '284,85'  c, '89,52'  d,  'E'    e from dual union all
      6  select '10258929' a, '4'  b, '323,85'  c, '89,52'  d,  'E'    e from dual union all
      7  select '10258930' a, '5'  b, '478,80'  c, '91,53'  d,  'E'    e from dual union all
      8  select '10258931' a, '6'  b, '436,67'  c, '78,09'  d,  'E'    e from dual union all
      9  select '10258932' a, '7'  b, '784,88'  c, '23,19'  d,  'E'    e from dual union all
     10  select '10258932' a, '8'  b, '100,88'  c, '11,11'  d,  'E'    e from dual union all
     11  select '10258932' a, '9'  b, '300,88'  c, '22,22'  d,  'F'    e from dual union all
     12  select '10258932' a, '10' b, '468,25'  c, '78,33'  d,  'F'    e from dual)
     13  select a, b, c, d, e, no_ds from
     14  (
     15    select a, b, c, d, e,
     16           case when c > 0 and e != 'F'
     17                then 'N'
     18           end no_ds
     19    from my_table)
     20  where no_ds = 'N' or e is null
     21  order by 1
     22  /
    
    A        B  C      D     E N
    -------- -- ------ ----- - -
    10258927 1  103,35 0
    10258929 3  284,85 89,52 E N
    10258929 4  323,85 89,52 E N
    10258930 5  478,80 91,53 E N
    10258931 6  436,67 78,09 E N
    10258932 7  784,88 23,19 E N
    10258932 8  100,88 11,11 E N
    
    7 Zeilen ausgewählt.
    
    SQL> 
    Does anyone have an idea?

    Oh, I read the title again once: 'remove double lines with different values.
    If it means that he is not specifically E and F values, but only if there is more than one distinct value, then you can do the following:

    with my_table as
    (
    select '10258927' a, '1'  b, '103,35'  c, '0'      d,   NULL  e from dual union all
    select '10258928' a, '2'  b, '0'       c, '15,19'  d,  'E'    e from dual union all
    select '10258929' a, '3'  b, '284,85'  c, '89,52'  d,  'E'    e from dual union all
    select '10258929' a, '4'  b, '323,85'  c, '89,52'  d,  'E'    e from dual union all
    select '10258930' a, '5'  b, '478,80'  c, '91,53'  d,  'E'    e from dual union all
    select '10258931' a, '6'  b, '436,67'  c, '78,09'  d,  'E'    e from dual union all
    select '10258932' a, '7'  b, '784,88'  c, '23,19'  d,  'E'    e from dual union all
    select '10258932' a, '8'  b, '100,88'  c, '11,11'  d,  'E'    e from dual union all
    select '10258932' a, '9'  b, '300,88'  c, '22,22'  d,  'F'    e from dual union all
    select '10258932' a, '10' b, '468,25'  c, '78,33'  d,  'F'    e from dual
    )
    --
    -- end-of-test-data
    --
    select a, b, c, d, e,
           num_distinct_values
    from
    (
      select a, b, c, d, e,
             count(distinct e) over (partition by a) num_distinct_values
      from my_table)
    where num_distinct_values <= 1
    order by 1
    / 
    

    The county notes how the distinct non-null values in column e for each one.
    Where clause then selects those with count = 0 (this is where e = null) and count = 1.
    If the number is greater than 1, different values exist for this id.

    Choose what fits your condition ;-)

  • How to read the data with different XML schemas within the unique connection?

    • I have Oracle database 11g
    • I access it via JDBC: Slim, version 11.2.0.3, same as xdb.
    • I have several tables, each has an XMLType column, all based on patterns.
    • There are three XML schemas different registered in the DB
    • Maybe I need to read the XML data in multiple tables.
    • If all the XMLTypes have the same XML schema, there is no problem,
    • If patterns are different, the second reading will throw BindXMLException.
    • If I reset the connection between the readings of the XMLType column with different schemas, it works.

    The question is: How can I configure the driver, or the connection to be able to read the data with different XML schemas without resetting the connection (which is expensive).

    Code to get data from XMLType is the implementation of case study:

     1   ResultSet resultSet = statement.executeQuery( sql ) ; 
    2   String result = null ;
    3    while(resultSet.next()) {
    4   SQLXML sqlxml = resultSet.getSQLXML(1) ;
    5   result = sqlxml.getString() ;
    6   sqlxml.free();
    7   }
    8   resultSet.close();
    9    return result ;

    It turns out, that I needed to serialize the XML on the server and read it as BLOB. Like this:

     1    final Statement statement = connection.createStatement() ;  2    final String sql = String.format("select xmlserialize(content xml_content_column as blob encoding 'UTF-8') from %s where key='%s'", table, key ) ;  3   ResultSet resultSet = statement.executeQuery( sql ) ;  4   String result = null ;  5    while(resultSet.next()) {  6   Blob blob = resultSet.getBlob( 1 );  7   InputStream inputStream = blob.getBinaryStream();  8   result = new Scanner( inputStream ).useDelimiter( "\\A" ).next();  9   inputStream.close(); 10   blob.free(); 11   } 12   resultSet.close(); 13   statement.close(); 14  15   System.out.println( result ); 16    return result ; 17
    

    Then it works. Still, can't get it work with XMLType in resultset. On the customer XML unwrapping explodes trying to pass to another XML schema. JDBC/XDB problem?

  • Insert/update the column with the clob data type

    Hi all

    ORCL Version: 11g.

    I have a table with the clob data type.

    Test12

    (col1 clob);

    I'm trying to insert/update to update the column with more than 4000 characters.

    But due to the limitation of tank 4000, I could not Insert/Update.

    Need your help in resolving this issue.

    THX

    Rod.

    The limit of 4000 characters is incorrect.  That pertains only to the varchar2 data type.  A clob can hold more than 4 G.

    Here is an example that shows how to insert it, I found...

    Otherwise, here is a way 'dirty' to do.

    insert into your_table (COLA, COLB)

    values

    (PRIMARY_KEY, PART 1 OF DATA)

    ;

    Update your_table

    Define COLB = COLB | PART 2 OF BIG DATA

    where COLA = PRIMARY_KEY;

    Update your_table

    Define COLB = COLB | PART 3 OF BIG DATA

    where COLA = PRIMARY_KEY;

    .. and so on...

    I don't know that I personally recommend the second style...  But he could do the job.

  • reuse of filters with different values

    We have a usage scenario where the same filters will have to be applied several times with different values. Looking the javadocs, it seems like there is no way to change the values of pre-packaged filters (EqualsFilter, GreaterFilter etc.). Is that correct or is there a way to do it? I see that if we use CohQL, we can use bind variables to do this. However, the use cases we should rather just more complex extractors ReflectionFilters.

    In addition, there no performance impact by using CohQL against java constructs directly?

    Thank you
    Manju.

    Hi Manju,

    While it is true that you cannot change values in the built in filters, even if you could it wouldn't make you save a lot on the construction of a new filter every time. I guess that if you build a very large number of filters, then you're going to create more garbage, but that shouldn't be a problem either. Some of the more specialized filters also contain State so that you do not want to resuse them.

    The main performance issue I know with CohQL which is only creates extractors of reflection so won't enjoy all serialized POF values you have. If you have indexed each value you want to query on using the same extractors relflection then it would help, but again, this means that everything you deserialization of the values for the query or insert to update the index.

    Kind regards
    JK

  • DAQmx create track (I-current-Basic) 8 channels with different values of Shunt resistance

    Hello

    I want to measure 8 current channels with different values of Shunt resistance.

    Problem: The channel create DAQmx (HAVE current Basic) specifies that a value of Shunt resistance.

    How can I set the value of Shunt resistance for each channel individually?

    Concerning

    Marcel

    Hi Marcel_C,

    Take a look to get attached.

    Best regards

    Mencef

  • Updated several lines with different values

    Hello!
    I have a problem. I need to update more than 1000 lines with different values. How can I do?
    For exsample I have table:
    ID; color, date,
    1 red
    2 green
    3 white

    I need to update the date field.

    Update table
    Set date = '01.02.03'
    where id = 1

    Update table
    Set date = '01.03.03'
    where id = 2


    Maybe it's how to update multiple rows in a single request?

    Sorry for my bad English.
    Thank you!

    Hello

    You can try this

    UPDATE TABLE SET DATE = CASE
                        WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
                        WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
                        END
    

    see you soon

    VT

  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

Maybe you are looking for

  • A30 does not start: missing file

    My A30 laptop will not load windows because the following file is missing or damaged. \System32\hal.dll. It is not currently connected to the internet, which should rule out a virus, and it has worked very well before receiving this message. (except

  • Motorola Xoom wifi Upgrade ICS

    I have participated on my D2 gingerbread update, and I also wanted to take part in the trial of impregnation ICS for my zoom of woman. Please thank you. If you can let me know what I need to do to take part in this.

  • can I send emails bulk from outlook express of thousands

    What is outlook express can send emails bulk

  • Windows will not use the disks of backup file to restore, get "unknown error."

    Backup done recently will not work when you try to restore the files.  System indicates an "unspecified error" has occurred.  No clue on what is blocking recovery?   Thank you

  • Transfer license to a PC 'death '.

    As for the other questions in this forum, I want to transfer a license from an existing to a new computer.  Installed Office Student/Home on my kids PC last year and my youngest daughter (who had the old PC) has finally bit the dust at the end of the