Removing columns from the result of a query via SQL

Hi
I have written a SQL query that returns the following results:
TableA
A1.ColA A2.ColB
1234 567
567 1234
I would like the query not to display the second row since the first row already has the required info.
The SQL query is
Select A1.ColA, A1.ColB
from TableA A1,
TableA A2
where A1.ColA <> A2.ColB
As you can see I'm comparing the values in the same column.
Regards
Bilal

As I can see none of the previously mentioned solutions here work in the proper way, so you can try this:
SQL> with t as (select 1234 colA, 5678 colB from dual union all
  2             select 5678 colA, 1234 colB from dual union all
  3             select 2 colA, 1 colB from dual union all
  4             select 1 colA, 3 colB from dual)
  5             select colA, colB
  6               from (select colA,
  7                            colB,
  8                            row_number() over(partition by least(colA, colB), greatest(colA, colB) order by colA) rn
  9                       from t)
10              where rn = 1
11  /
      COLA       COLB
         2          1
         1          3
      1234       5678

Similar Messages

  • Querying from the result of another query.

    The following query gives me a list of FaxIDs whose file path column does not start with C:\ and that haven't already been identified according to the identified table.
    SELECT [FaxID] FROM [FaxQueue]
    WHERE [FilePath] NOT LIKE 'C:\%'
    AND [FaxID] NOT IN (SELECT [FaxID] FROM [Identified]);
    I have some more code that send's an email to alert whoever that the following records don't have a correct filepath.
    Now the list of FaxIDs need to be re-used to insert into the identified table. The identified table has just one column which keeps track of which FaxIDs that have been identified as not having a falid file path.
    INSERT INTO [identified] VALUES (???)
    I don't know what to stick in for the ?s... do I simply copy and paste my first query into the question marks?
    How can I "save" the list of FaxIDs from the first query into some kind of data structure so I can send them in an e-mail (sp_send_dbmail)?
    -Nothing to see. Move along.

    We have 3 possible ways,
    1. As subquery.
    SELECT * FROM (
    SELECT [FaxID]
    FROM [FaxQueue]
    WHERE [FilePath]
    NOT LIKE 'C:\%'
    AND [FaxID]
    NOT IN (SELECT
    [FaxID] FROM
    [Identified])
    ) X
    2. Using CTE(common table expression)
    ;WITH CTE AS (
    SELECT [FaxID]
    FROM [FaxQueue]
    WHERE [FilePath]
    NOT LIKE 'C:\%'
    AND [FaxID]
    NOT IN (SELECT
    [FaxID] FROM
    [Identified])
    SELECT * FROM CTE
    3. USING TEMP TABLE.
    SELECT [FaxID] INTO #TEMPTABLE
    FROM [FaxQueue]
    WHERE [FilePath]
    NOT LIKE 'C:\%'
    AND [FaxID]
    NOT IN (SELECT
    [FaxID] FROM
    [Identified]);
    SELECT * FROM #TEMPTABLE
    Regards, RSingh

  • How can I remove the Location column from the search results in a .chm file?

    How can I remove the Location column from the search results in a .chm file?
    I generated the file in Robohelp HTML 9.
    As far as I know it's used when you've combined more than one source into the final help file. It is possible (though I don't remember doing it) that I did that once a couple of years ago but now I'm only using one source - the project that's generating the .chm.
    Can anyone tell me how I can remove it?
    Thanks
    Tom

    In Project Setup look at the Window properties. I think you will find Advanced Search is ticked.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Removing ?xml version="1.0"? from the result

    Hi Friends
    How do we remove <?xml version="1.0"?> from the result if we have ran two query in one resultset
    e.g
    qryCtx := DBMS_XMLGEN.newContext('select ename, job from emp where empno > 7900');
    DBMS_XMLGEN.setRowSetTag(qryCtx,'employeedata');
    DBMS_XMLGEN.setRowTag(qryCtx,'emp');
    result := DBMS_XMLGEN.getXML(qryCtx);
    insert into temp_clob_tab values(result);
    DBMS_XMLGEN.closeContext(qryCtx);
    qryCtx := DBMS_XMLGEN.newContext('select * from dept');
    DBMS_XMLGEN.setRowSetTag(qryCtx,'departments');
    DBMS_XMLGEN.setRowTag(qryCtx,'dept');
    result := DBMS_XMLGEN.getXML(qryCtx);
    insert into temp_clob_tab values(result);
    DBMS_XMLGEN.closeContext(qryCtx);
    RESULT
    <?xml version="1.0"?>
    <employeedata>
    <emp>
    <ENAME>FORD</ENAME>
    <JOB>ANALYST</JOB>
    </emp>
    <emp>
    <ENAME>MILLER</ENAME>
    <JOB>CLERK</JOB>
    </emp>
    </employeedata>
    <?xml version="1.0"?>
    <departments>
    <dept>
    <DEPTNO>10</DEPTNO>
    <DNAME>ACCOUNTING</DNAME>
    <LOC>NEW YORK</LOC>
    </dept>
    <dept>
    <DEPTNO>20</DEPTNO>
    <DNAME>RESEARCH</DNAME>
    <LOC>DALLAS</L[i]Long postings are being truncated to ~1 kB at this time.

    Why do you want to get rid of the XML header ? If you want to concatenate the two values to produce a single XML document, I would recommend using XMLConcat or XMLAgg SQL functions.
    - Ravi

  • Virtual column in the result set of the query.

    Hi folks,
    I have table , let it be, EMP. It has columns ENAME,EMPNO,JOB etc.,
    My requirement is to add an extra column, not present in the table, having NULL value at the time of diplaying the results of a query. I hope you got it. So a column that does not exists in the table should get displayed in the resultant set when we query the results from that table. so my question is, how to write the SELECT statement using that virtual column.
    I'd thought of using X column in Dummy table but what if I don't have any dummy table in my particular schema.
    Please do revert back with the solution.
    Your effort'll be genuinely appreciated.
    Cheers
    PCZ

    Hi,
    If you just wany display null values you can write query like this :
    SELECT ENAME,EMPNO,JOB , NULL DUMMY_COLUMN FROM emp;
    Regrads
    Avinash

  • Problem of running the jump query from the result line

    Dear expert,
    I have a problem when running a jump query from the result line. Apparently, the values of the caracteristics haven't been sent to the jump target.  However, the configuration in RSBBS seems to be good as the jump works well from the other lines.
    Does anyone have some ideas on that?
    Thanks in advance!

    Hi,
    If you are supposed to bring across characteristic values to your target, then you will not be able to jump from the result line. The configuration expects that the values of the characteristic marked as being used in the jump are filled with unique values. When you use the result line as a source for your jump, the values in the result line will most likely be based on the sum of multiple characteristic values.
    Hth,
    -Jacob

  • Passing a query-limit-value to a Computed-Column on the Results Page

    Hello All,
    Is it possible to use a user-selected variable-limit (filter), and pass it to an IF statement in a Computed-Column in a Results Screen.
    Example:
    I have a Computed Column in a Results screen which uses the following logic:
    if ( Accounting_Period == "2" && Ledger == "ACTUALS" ) {Year_to_Date_Actuals} else (0)
    Instead of [Accounting_Period == "2"], I would like to set Accounting_Period == <variable_query_limit>
    How would one do this?
    Thanks!
    smg

    if not using a dashboard you may want to look at the OnPostProcess event and put script there to collect the selected value of the limit and modify the computed column of the results section.
    strongly recommend you review documentation

  • How to execute a procedure depending on the result of a query?

    Hello, I'm new in ODI.
    I want to execute a procedure depending on the result of a query Oracle table.
    We have a Oracle Table whit a column that contains two possibles values.
    I want read the table, row by row, and depending on this value, execute a Procedure or execute another.
    How can i do?

    what you need to do is
    1. create a variable which "new_var2" which has the count of the number of rows you want to process. must be data type numeric.
    2. copy "new_var2" to the package screen.
    3. duplicate the "new_var2" on the package screen and evaluate the variable and test for "> 0" zero, call it "new_var2_E"
    3. create a new odi variable "new_var1" with a refresh of "select field1 fom (select field1,rownum as rownumber from tablex) where rownumber = #new_var2" in the relevant schema and technology.
    4. copy "new_var1" into your package (some where in the flow)
    5. right click the "new_var1" variable in you package screen and you should get the option duplicate step (click on that)
    6. select the the duplicate "new_var1" on the package screen and correct the the name to something meaning full to you "new_var1_E", also change the "type" to "evaluate variable" then you should see a "value" box. enter one of the values you want to test in the box (remember do not put in quotes ' )
    7. now back on the package screen join the "new_var1" to the "new_var1_E" with an OK line
    8 you now join "new_var2" to "new_var2_E" with OK
    9 you join "new_var2_E" to "new_var1"
    10. you then join the "new_var1_E" with an OK or a KO line to the relevant procedure.
    12. you need to duplicate "new_var2" in the package screen one more time this time and call it "new_var2_D" set the type to evaluate and then select the increment of -1
    13. the relevant procedure to "new_var2_D" with an OK
    14. join the "new_var2_D" to the "new_var2_E" with an OK
    15. this should close off the loop now the exit point is "new_var2_E" with a KO line to the next part of your process....
    Basically you should end up with a loop on new_var2 decementing, and it is used to get a specific next record row from your table.
    Hope this helps, sorry it is a little long winded..
    Edited by: DavidGD on Feb 8, 2009 3:29 PM

  • Can I use the result of a query in another query of the same cube?

    Hello everybody;
    I have the following case. In query "A", I have used in rows a structure, whit a last formula named “Total A”, in another query "B", I need to used the result of “Total A”.
    Can anybody help me?
    Thanks in advanced.
    Mariana Serrano

    Hi Mariana,
    You can change local structures into reusable structures in any existing query by selecting the structure and, choosing Save as... from the context menu and then entering a technical name and a description in the Save Structure as... dialog box.
    You can change reusable structures that you are using in a query into local structures by selecting the structure and choosing Remove Reference from the context menu.
    Also go through this link:
    http://help.sap.com/saphelp_sem40bw/helpdata/en/e3/e60138fede083de10000009b38f8cf/frameset.htm
    Best Regards,
    DMK
    *Assign point if it helps...

  • Insert a Blank Column in the Results Area of a Workbook

    Is it possible to insert a blank column in the results area of a WORKBOOK that does not get affected by free characteristic drill down or refreshing of the corresponding query?  The current workbook looks like follows
    Column A - Characteristic1
    Column B - Characteristic2
    Column C - KeyFigure1
    Column D - KeyFigure2
    Column E - KeyFigure3
    Column F - KeyFigure4
    The requirement is that the user wants to enter some estimates between Column B and Column C and Column D and Column E as follows
    Column A - Characteristic1
    Column B - Characteristic2
    Column C - USER ENTRY
    Column D - KeyFigure1
    Column E - KeyFigure2
    Column F - USER ENTRY
    Column G - KeyFigure3
    Column H - KeyFigure4
    Column I - CALCULATIONS BASED ON USER ENTRY
    First I tried to split the results area and save the workbook.  But when the query is refreshed then the entire results area gets back in one piece.  I succeeded partially by having a key figure with no possible output (i.e., restricting a non-existent value on a characteristic).  Again in here, whatever user inputs will get wiped out with the drill down.  Does any one have any pointers?  Thanks.
    IS

    Hi IS,
    As a nearly workaround I can suppose to do the following.
    Create two identical requests.
    In the first one hide the columns to the right from your intended new user column. In the second one - hide columns to left.
    Knowing the columns number to be shown in each request you can place both request in the same row, but in different columns taking into account that between result areas should be one (or more) additional column.
    Data entered by a user will not be wiped out during query refresh or drilldown. Of course, these user data will not conform drilldown operations. So, it is not 100% solution you want.
    Another possibility, very hard to implement (if feasible at all), is to write VB code that will monitor user action and will keep data entered by a user somewhere in another sheet and restore them in proper cells after user action (drilldown). But I don't think such coding worth it.   
    Best regards,
    Eugene

  • Import Metadata Wizard won't remove columns from repository table

    Hello everybody!
    We are facing the following problem with an imported object in OWB:
    I have imported successfully a table into OWB. I can see in the OWB's "Data Object Editor" that the repository object is identical to the physical object.
    If I remove a column from the physical table in db and re-Import the table in OWB, the OWB "Import Metadata Wizard" understands that a column is removed and in the "Import Results" shows that column as "Preserved". However, in OWB's "Data Object Editor" the column is not removed!! Is there a step we are missing?
    Thanks in advance!!
    ps: we are using OWB 10gR2

    Yes you missed one step
    While Importing on
    Step 3 of 3 Summary and Import
    Click on Advance Import OPtion
    De select all the preserve option.
    (Mark it as helpful or correct if it is )
    Cheers
    Nawneet

  • Getting the actual size of the result of a query

    Hi,
    I would like to ask if someone knows on how to get an estimate size of the result of a query on a table. To make it more specific, here is an example.
    Let us say I have this table called EMP and it has a column called DATE. I have issued a query like this:
    select * from EMP where DATE < to_date('01-AUG-08');
    I want to get the actual size of the result of the query in bytes or MB. How would i achieve this without creating another table and transferring the data on it.

    You can use SQL*Plus Autotrace to have the data size sent between client and database session:
    SQL> set autotrace traceonly statistics;
    SQL> select * from employees where hire_date < to_date('01/08/08');
    107 rows selected.
    Statistics
            430  recursive calls
              0  db block gets
            123  consistent gets
             11  physical reads
              0  redo size
           9405  bytes sent via SQL*Net to client
            457  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
              3  sorts (memory)
              0  sorts (disk)
            107  rows processed
    SQL>Edited by: P. Forstmann on 25 janv. 2011 18:55

  • How can I remove files from the startup disk

    I am getting a screen when I am trying to quit saying   the "MAC OS X startup disk has no more space available for application memory"  by closing the windows and removing files from the startup disk will help.
    How do I do this?

    That error message is misleading. Your problem is excessive swapping of data between physical memory and virtual memory.
    That can happen for two reasons:
    You have a long-running process with a memory leak (i.e., a bug), or
    You don't have enough memory installed for your usage pattern.
    Tracking down a memory leak can be difficult, and it may come down to a process of elimination.
    In the Activity Monitor application, select All Processes from the menu in the toolbar, if not already selected. Click the heading of the  Real Mem column in the process table twice to sort the table with the highest value at the top. If you don't see that column, select
    View ▹ Columns ▹ Real Memory
    from the menu bar.
    If one process (excluding "kernel_task") is using much more memory than all the others, that could be an indication of a leak. A better indication would be a process that continually grabs more and more real memory over time without ever releasing it. Here is an example of how it's done.
    The process named "Safari Web Content" renders web pages for Safari and other applications. It uses a lot of memory and may leak if certain Safari extensions or third-party web plugins are installed. Consider it a prime suspect.
    If you don't have an obvious memory leak, your options are to install more memory (if possible) or to run fewer programs simultaneously.
    The next suggestion is only for users familiar with the shell. For a more precise, but potentially misleading, test, run the following command: 
    sudo leaks -nocontext -nostacks process | grep total
    where process is the name of a process you suspect of leaking memory. Almost every process will leak some memory; the question is how much, and especially how much the leak increases with time. I can’t be more specific. See the leaks(1) man page and the Apple developer documentation for details.

  • Add and remove columns from JTable

    Help me please!
    A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
    I completely confused with it.....
    Here is my code for remove column:
    class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
                   else
                          JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         }

    It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
    My brain is boiled, I've try a lot of variants of code, but did't get right result :((
    It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
    I understand, that my code just hide columns, not delete from table model....
    But now I have not any decision of my problem...
    Thanks a lot for any help. :)
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.table.DefaultTableModel;
    class JTableF extends JFrame
         Object [] [] data = new Object [0] [2];
         JTable table;
         DefaultTableModel model;
         String [] columnNames = {"1", "2"};
         TableColumnModel cm;
         JTableF()
              super("Table features");
              setDefaultLookAndFeelDecorated( true );
              setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar MBar = new JMenuBar();
              JMenu [] menus =  {new JMenu("A"), new JMenu("B")};
              JMenuItem [] menu1 =  {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'),  new JMenuItem("Add column"), new JMenuItem("Delete column")};
              menu1 [ 0 ].addActionListener(new AddL());
              menu1 [ 1 ].addActionListener(new DelL());
              menu1 [ 2 ].addActionListener(new AddC());
              menu1 [ 3 ].addActionListener(new DelC());
              for (int i=0; i<menu1.length; i++)
                   menus [ 0 ].add( menu1 [ i ]);
              for (int i=0; i<menus.length; i++)
                   MBar.add(menus );
              JPanel panel = new JPanel ();
              model = new DefaultTableModel( data, columnNames );
              table = new JTable (model);
              cm = table.getColumnModel();
              panel.add (new JScrollPane(table));
              JButton b = new JButton ("Add row button");
              b.addActionListener(new AddL());
              panel.add (b);
              setJMenuBar (MBar);
              getContentPane().add(panel);
              pack();
              setLocationRelativeTo (null);
              setVisible (true);
         class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
                             tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
                        //cm = tableCModel;
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         class AddC implements ActionListener
              public void actionPerformed (ActionEvent e)
                   //table.setColumnModel(cm);
                   Object NewColumnName = new String();
                   NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
                   int i = model.getRowCount();
                   int j = model.getColumnCount();
                   Object [] newData = new Object [ i ];
                   model.addColumn ( NewColumnName, newData);
         class AddL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int i = model.getColumnCount();
                   Object [] Row = new Object [ i ];
                   model.addRow ( Row );
         class DelL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int [] HowManyRowsDelete = table.getSelectedRows();
                   if (HowManyRowsDelete.length !=0)
                        for (int k = HowManyRowsDelete.length-1; k>-1; k--)
                             model.removeRow (HowManyRowsDelete[k]);
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
         public static void main (String [] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        JTableF inst = new JTableF();

  • Removed coloumns from the table

    How to get the removed columns from a table

    905310 wrote:
    How to get the removed columns from a tableYour question is not clear enough.
    As per my understanding you want to restore the deleting columns?
    What is the Database Version?
    If you have backup in dump file, import it.
    If you do not have any dumpfile, You have to restore from Latest backup(RMAN). Of course you have to restore database as you cannot restore objects(tables) from RMAN backup.

Maybe you are looking for