Resukt:Get number of rows from 3 different table...?

Hi All,
I need to find out number of rows from 3 different table for the same conditions. Instead of writing 3 queries, is it possible to get it thru one query?
For example, i need to find out number of rows in tables where name = 'Ameet' from 3 different table, i will end writing 3 queries.
1. select count(1) from table_a where name = 'Ameet';
1. select count(1) from table_b where name = 'Ameet';
1. select count(1) from table_c where name = 'Ameet';
Is it possible to write a single query to get result of all above 3 queries?
result:
table_a table_b table_c
34 44 2

One way:
SELECT      (SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet') AS TABLE_A
,     (SELECT     COUNT(*) AS CNT FROM TABLE_B WHERE name='Ameet') AS TABLE_B
,     (SELECT     COUNT(*) AS CNT FROM TABLE_C WHERE name='Ameet') AS TABLE_C
FROM DUALIf you want the total:
SELECT     SUM(CNT)
FROM
     SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet'
     UNION ALL
     SELECT     COUNT(*) FROM TABLE_B WHERE name='Ameet'
     UNION ALL
     SELECT     COUNT(*) FROM TABLE_C WHERE name='Ameet'
)

Similar Messages

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • Count of rows from different tables.

    Hi Friends,
    I have 4 tables with a common column name "ID". I would like to get the count of rows from all the four tables which has the same ID.
    Ex
    select count(a.id) from table1 a,table2 b,table3 c,table4 d where a.id=b.id=c.id=d.id=5;
    please suggest me some solution

    may be thsi?
    select count(a.id) from table1 a,table2 b,table3 c,table4 d
    where a.id=b.id and a.id=c.id and a.id=d.id and a.id=5;

  • Get Number of rows from a sql query.

    I am reading data from a sql query in a BLS transaction and I would like to know the number of rows returned.
    Is there an easy way to do this without looping through the table?
    Thanks Jasper

    Hi Jasper,
    You can use the XPATH count function similar to  this:
    GetTagList.Results{count(/Rowsets/Rowset/Row)}
    Kind Regards,
    Diana Hoppe

  • How can I get Number of Lines from internal table?

    Hello at all,
    i have in my Report a internal Table, which have many KUNNR.
    For example the internal Table:
    MANDT.......KUNNR......NAME.........FIRSTNAME........CITY
    ...040..........12345.........Owen............Michael........Liverpool
    ...040..........12345.........Owen............Michael........Liverpool
    ...040..........99999.......Johnson.......... Jeffrey........London
    ...040..........12345.........Owen............Michael........Liverpool
    ...040..........55555.......Hardley.......... Kingston.......Birmingham
    I want to know, how many same KUNNR are existing in the internal Table?
    In my example i need the result 3, because their is existing 3 times the Kunnr 12345 in the internal Table.
    Have anyone an idea, how can I resolve this problem?
    Edited by: Thomas Zloch on Jun 21, 2010 2:55 PM - one question mark at a time is sufficient

    Hi,
    1.Create two internal tables of same type and sort according to Kunnr then Delete the
    adjusent duplicates by comparing KUNNR
    2.Sort the table by KUNNR and use ON change of Concept in that Just increment the counter.
    I am writing the sample logic here.
    tables kna1.
    data: t_kna1 type table of kna1,
             w_kunnr type kna1-kunnr,
             counter type i," Holds No.of KUNNRs in the T_kna1
             t_kna2 type table of kna1.
    select * from kna1 into table kna1 up to 100 rows.
    t_kna2[] = t_kna1[].
    delete t_kna2 by kunnr.
    delete adjusent duplicates from t_kna2 by comparing kunnr."1st Method
    read table t_kna2 transporting no-fields.
    counter = sy-tfill."1st Method
    loop at t_kna1 into kna1."2nd Method
    at first.
    w_kunnr = kna1-kunnr .
    counter = 1.
    endat.
    if w_kunnr ne kna1-kunnr.
    counter = counter + 1.
    endif.
    endloop.
    Note : Here I used a sample table KNA1 in this there are no Duplicates of KUNNR .

  • Adobe form from webdynpro : Getting a single row in the table

    Hello,
    I have a scenario in which I have to create a adobeform from webdynpro application.
    I have created the form and have the context designed in place.
    I am facing a problem in the table I have in my adobeform.
    I am adding rows to this table dynamically using a button using "addInstance"
    Now on the webdynpro side , when I try to read this table I get a single row from this table.
    This row is always the first row of that table.
    I checked the following things from blog   /people/juergen.hauser2/blog/2006/09/12/avoiding-common-mistakes-when-using-tables-on-sap-interactive-forms  , i.e. :
    Cardinality of the node.
    Tick on the option "Repeat Row for Each Data Item".
    But still no success.
    With deadlines to catch I had to post this question after trying a lot.Please help.

    Hello Otto,
    I had found this link before and used the same solution , but unfortunately is taking a long time.
    Now what I am doing is :
    1. I append 10 rows into the table then bind it to the node
    2. Then on the adobe form I have removed the check on "Add row for each line item" because of which it shows only 1 row 
         on the form.
         Now I add rows dynamically, but this puts a limit on the number of rows can be added to the table i.e. 10.
    But this again has added problems like while displaying the form or modifying I hav to handle it seperately and cannot use the same form as it is.( as I have removed the tick for "Add row for each line item" ).
    Thanks,
    Omkar Mirvankar

  • How to get multiple rows from database table?

    hello !
    I need to get multiple rows from a OLEDB database table and display them on a table object.
    I did "Wrap in subfrom" on the table,  set  subform of the table to "flowed", and checked "Repeat row for each data item" of Row1 of the table.
    But I can get only one row on the table object.
    I need your help.
    Thanks

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • Deleing large number of rows from table

    Hi,
    Consider tables A,B,C,D,E,F. all are having 100000++ records Tables B,C,D are dependent on table A (with foreign key constraint). When I am deleting records from all tables, table B,C,D are taking max 30-40 seconds while table A is taking 30-40 mins. All tables are having indexes.
    Method I have used:
    1. Created Temp table
    2. then deleted all records from B,C,D,E,F for all records in temp table for limit of 500.
    delete from B where exists (select 1 from temp where b.col1=temp.col1);
    3. please suggest options for me why it is taking too much time for deleting records in table A.
    Is there any thing that during deleting data from such master table, it is reffering to all dependent tables even if dependent data is not present ??? If yes then couls you please please suggest options for me to remove this ? I hope it won't go for CHECK constraints during deleting data.
    Thanks,
    Avinash
    Edited by: user12952025 on Apr 30, 2013 2:55 AM
    Edited by: user12952025 on Apr 30, 2013 2:56 AM
    Edited by: user12952025 on Apr 30, 2013 2:57 AM

    user12952025 wrote:
    Hi,
    Consider tables A,B,C,D,E,F. all are having 100000++ records Tables B,C,D are dependent on table A (with foreign key constraint). When I am deleting records from all tables, table B,C,D are taking max 30-40 seconds while table A is taking 30-40 mins. All tables are having indexes.What attribute of the Foreign key is specified? Is it On Delete Cascade? If yes, then in a way, deleting data fro Child tables is un-necessary. Only a Delete from parent shall suffice.
    >
    Method I have used:
    1. Created Temp table
    2. then deleted all records from B,C,D,E,F for all records in temp table for limit of 500.
    delete from B where exists (select 1 from temp where b.col1=temp.col1);
    3. please suggest options for me why it is taking too much time for deleting records in table A.
    Is there any thing that during deleting data from such master table, it is reffering to all dependent tables even if dependent data is not present ??? If yes then couls you please please suggest options for me to remove this ? I hope it won't go for CHECK constraints during deleting data.One another way is to "Switch-Off" the relationship while deleting the data.
    ALTER TABLE table_name
    disable CONSTRAINT constraint_nameAnd then Delete the data from each of tables.
    You did specify the number of rows in each table, it would have been better to mention the number of rows to be deleted.
    It is not a hard-and-fast way, but would generally perform better, to copy the data (to be retained) from Parent Table into a Temporary Table, Drop Parent Table and rename teh Temporary table to parent table. Similar can be performed on Child tables.
    You may then Enable the Foreign key constraints.

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • How NOT to restrict no of rows from two tables

    I have two identical tables Invoice and Payment. The only difference is Invoice_id,Invoice_Amt and Payment_id,Payment_Amt columns that shows different ids and amounts. The bank_ids, names, account_types are same. Invoice table has 3 rows and Payment has 2. Simply meaning that there were 3 invoices generated but the bank received 2 payments. I want to show Invoice_Amt and Payment_Amt using sql query. But its giving me total 6 rows. Whereas, I want 3 from Invoice and 2 rows from Payment table to show side-by-side.
    CREATE TABLE invoice
    ( invoice_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    invoice_amount NUMBER);
    ----Invoice table has 3 rows showing 3 Invoice Amts
    CREATE TABLE payment
    ( payment_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    payment_amount NUMBER);
    ----Payment table has 2 rows showing 2 Payments
    After executing this sql statement below, I get 6 rows:
    select inv.invoice_amount,pymt.payment_amount from invoice inv,payment pymt where inv.bank_id=pymt.bank_id;
    How can I show 3 rows for Invoice and 2 for Payment..?
    Thank you.

    Hi,
    So you want
    the 1st invoice to appear side-by-side with the 1st payment,
    the 2nd invoice to appear side-by-side with the 2nd payment,
    the nth invoice to appear side-by-side with the nth payment.
    But, if there are an uneqaul numner of payments and invoices, all the payments and all the invoices must still be shown, alone on a row if necessary.
    That sounds like a job for FULL OUTER JOIN.
    Use the analytic ROW_NUMBER fucntion to determine which is the 1st, 2nd, ..., nth row in each table, for each bank.
    WITH     invoice_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      invoice_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          invoice_id
                           )         AS r_num
         FROM    invoice
    ,     payment_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      payment_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          payment_id
                           )         AS r_num
         FROM    payment
    SELECT       NVL (i.bank_id,   p.bank_id)          AS bank_id
    ,       NVL (i.bank_name, p.bank_name)     AS bank_name
    ,       i.invoice_amount
    ,       p.payment_amount
    FROM          invoice_plus_r_num     i
    FULL OUTER JOIN     payment_plus_r_num     p  ON   i.bank_id     = p.bank_id
                                        AND     i.bank_name     = p.bank_name
                                AND     i.r_num          = p.r_num
    ORDER BY  bank_id     -- you can use column aliases here
    ,       bank_name
    ,       NVL (i.r_num, p.r_num)
    ;You mentioned something about accounts, but didn't include that in the CREATE TABLE statements. You'll probably want to add that wherever I used bank_id and bank_name, above.
    Are invoce and payment actually views, rather than tables? If not, you should have a separate bank table, and only include the bank_id in the other tables.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Feb 3, 2011 12:32 PM

  • How to find number of rows in a table

    i have one table ,it contains millions of record,how can i know number of rows in that table without using count(*),
    i tried in user_table ,for the column NUM_ROWS,but it is not showing number of rows,pls send me a solution for this.
    regards,
    singh

    Ok, that only was to show simply that max option
    might not an option to reduce execution time.Yes, but I/O variances have a tendency to really skew the observed elapsed execution time - making execution time alone a poor choice to determine what SQL will perform better than another.
    Both MAX(ROWNUM) and COUNT(*) results in the same amount of I/O - as both uses the exact same execution plan, I/O wise. In this example, a FTS.
    SQL> create table testtab nologging as select * from all_objects where rownum < 10001;
    Table created.
    -- warmed up the buffer cache with a couple of SELECTs against TESTAB in order
    -- to discard PIOs from the results
    SQL> set autotrace on
    SQL> select count(*) from testtab;
    COUNT(*)
    10000
    Execution Plan
    Plan hash value: 2656308840
    | Id | Operation | Name | Rows | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 35 (9)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | | |
    | 2 | TABLE ACCESS FULL| TESTTAB | 9262 | 35 (9)| 00:00:01 |
    Note
    - dynamic sampling used for this statement
    Statistics
    0 recursive calls
    0 db block gets
    131 consistent gets
    0 physical reads
    0 redo size
    223 bytes sent via SQL*Net to client
    238 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    SQL> select max(rownum) from testtab;
    MAX(ROWNUM)
    10000
    Execution Plan
    Plan hash value: 2387991791
    | Id | Operation | Name | Rows | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 35 (9)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | | |
    | 2 | COUNT | | | | |
    | 3 | TABLE ACCESS FULL| TESTTAB | 9262 | 35 (9)| 00:00:01 |
    Note
    - dynamic sampling used for this statement
    Statistics
    0 recursive calls
    0 db block gets
    131 consistent gets
    0 physical reads
    0 redo size
    225 bytes sent via SQL*Net to client
    238 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    So seeing that we have the exact same baseline for both queries, and that PIO does not influence the results, we time a 1000 executions of both.
    SQL> declare
    2 cnt number;
    3 begin
    4 for i in 1..1000
    5 loop
    6 select count(*) into cnt from testtab;
    7 end loop;
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.19
    SQL>
    SQL> declare
    2 cnt number;
    3 begin
    4 for i in 1..1000
    5 loop
    6 select max(rownum) into cnt from testtab;
    7 end loop;
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:15.87
    SQL>
    This shows that what makes the MAX() more expensive is just that - determining the MAX(). For each row, Oracle has to call its internal MAX() function with two values - the current max result and the new value. This function then returns the new max value. This overhead per row adds up to a significant overhead in execution time - making the MAX() approach 5x slower than the COUNT() approach.

  • Copying table rows from one table to another table form

    Hi
    I have a problem about Copying table rows from one table to another table form.On jsf pages if you enter command button go anather jsf page and it copy one row to another table row. But when i execute this process for table FORM it doesn't copy I wrote a code under "createRowFromResultSet - overridden for custom java data source support." Code block is:
    ViewRowImpl value = super.createRowFromResultSet(qc, resultSet);
    try{
    AdfFacesContext fct = AdfFacesContext.getCurrentInstance();
    Number abc = (Number)fct.getProcessScope().get("___");
    value.setAttribute("___",abc);
    }catch(Exception ex){System.out.println(ex);  }
    return value;

    Table may be copied with the
    expdp and impdp utilities.
    http://www.oracle.com/technology/products/database/utilities/index.html

  • Deleting a row from parent table

    Dear Guru's
    I am having two table with parent - child relationship. My problem is when I am deleting a row from parent table the curresponding child row from child table also should be deleted.
    My Primary table 'Employee, EMPID Primary key
    Child table 'Privilage' inthis EMPID referencing the EMPID of Employee table
    My need is when I am deleting a row from parent table the curresponding child row from child table also should be deleted
    I issued the SQL query like,
    delete from employee where empid='12345' cascade constraints;
    Then it showing me error like,
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    Please resolve my issue , Its Top urgent
    Thanks & Cheers
    Antony

    Choosing How Foreign Keys Enforce Referential Integrity
    Oracle Database allows different types of referential integrity actions to be enforced, as specified with the definition of a FOREIGN KEY constraint:
    Prevent Delete or Update of Parent Key The default setting prevents the deletion or update of a parent key if there is a row in the child table that references the key. For example:
    CREATE TABLE Emp_tab ( 
    FOREIGN KEY (Deptno) REFERENCES Dept_tab);Delete Child Rows When Parent Key Deleted The ON DELETE CASCADE action allows parent key data that is referenced from the child table to be deleted, but not updated. When data in the parent key is deleted, all rows in the child table that depend on the deleted parent key values are also deleted. To specify this referential action, include the ON DELETE CASCADE option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE CASCADE); Set Foreign Keys to Null When Parent Key Deleted The ON DELETE SET NULL action allows data that references the parent key to be deleted, but not updated. When referenced data in the parent key is deleted, all rows in the child table that depend on those parent key values have their foreign keys set to null. To specify this referential action, include the ON DELETE SET NULL option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE SET NULL);
    SQL> conn scott/tiger
    Connected.
    SQL> create table ppk ( no number primary key);
    Table created.
    SQL> begin for inn in 1..10 loop insert into ppk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> create table ffk ( no number references ppk(no));
    Table created.
    SQL> begin for inn in 1..10 loop insert into ffk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> drop table ppk cascade constraints;
    Table dropped.Message was edited by:
    user52
    Message was edited by:
    user52
    Message was edited by:
    user52

  • Displayin message and fixing the number of rows in a table

    Hi Experts,
    I have a requirement like this
    there is a table, where i need to diplay a message when there are no records and no rows should be visible on that table.
    Also, when the records are populated from the context, i need to fix the number of rows in that table and display the records.
    Please let me know hw this can be achieved.
    Also in the table I have Link to URL, please let me know how to handle this reference, when i set the reference Property, its giving me an error stating that the file doesn't exist when the table gets loaded.
    Thanks in Advance
    Regards,
    Palani

    Hi
    Oh!!  You should to  explain it at first thread itself that you want to display a JPG imange or other WDWebResourceTypetaken form the backend.
    1. So this is not at all a URL
    2. You have to convert binary data to WDWebResource then display it in either Image UI element or other (like PDF , txt etc)
    3
    try
                   //        Read the datasource of the FileUpload
                   IWDResource res = wdContext.currentContextElement().getResource();
                   InputStream in = res.read(false);
                   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                   int length;
                   byte[] part = new byte[10 * 1024];
                   while ((length = in.read(part)) != -1)
                        bOut.write(part, 0, length);
                   in.close();
                   bOut.close();
                   IPrivateUploadCompView.IImageTableElement ele = wdContext.nodeImageTable().createImageTableElement();
                   ele.setImage(wdContext.currentContextElement().getResource().getUrl(0));
                   ele.setText(res.getResourceName());
                   wdContext.nodeImageTable().addElement(ele);
              catch (Exception e)
                   wdComponentAPI.getMessageManager().reportWarning(e.toString());
    Here I assume that you convert that data to IWDResource type or
    4.
    WDWebResource.getWebResource(wdContext.currentContextElement().getresource(), type);
    // getResource of type binary which u read from BAPI and set it in local context , type is MIMETYPE or hardcode it as "JPG"
    5. Further help
       [Help1|To Displayan Image in Webdynpro Java from Standard Function Module;
    [Help2|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumentstobeusedinWeb+Dynpro]
    [Help3|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumenttobeusedinWeb+DynPro]
    It might code look strange at first , please do some reserch in SDN ,I did my best at this level.
    Best Regards
    Satish Kumar

  • Getting 2nd Least Value from Different Column

    Hi there All,
    I have one odd requirement.
    I hava table which has diffrent columns of numeric Datatype.
    The task is to get the least values from the table.
    I can take the least value by least(col1,col2,col3 ...) function.Until this stage it is fine.
    But also I have take 2nd least value and 3rd least value, which I am quite unsure how to get it.
    Looking forward for suggestions.
    Thanks in Advance.
    Regards,
    Ajeet

    The following is a generic solution that will allow you to select the nth least and allow you to pass as many column names as you like and will return null if the nth least requested exceeds the number of distinct values. The nleast function that I wrote uses the str2tbl function by Tom Kyte. I have included a demonstration of its usage below. The value returned for the 1st least is the same as that returned by the least function.
    This should have been posted on the SQL and PL/SQL discussion group of these forums, rather than the general database. I also posted the same response in the SQL discussion group of the Orafaq forums.
    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM your_table
      2  /
          COL1       COL2       COL3
             1          2          3
             4          6          5
             8          7          9
            11         12         10
            15         13         14
            18         17         16
    6 rows selected.
    scott@ORA92> -- type and functions:
    scott@ORA92> create or replace type myTableType as table of number;
      2  /
    Type created.
    scott@ORA92> create or replace function str2tbl( p_str in varchar2 )
      2  return myTableType
      3  as
      4        l_str      long default p_str || ',';
      5        l_n         number;
      6        l_data    myTableType := myTabletype();
      7  begin
      8        loop
      9            l_n := instr( l_str, ',' );
    10            exit when (nvl(l_n,0) = 0);
    11            l_data.extend;
    12            l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
    13            l_str := substr( l_str, l_n+1 );
    14        end loop;
    15        return l_data;
    16  end;
    17  /
    Function created.
    scott@ORA92> CREATE OR REPLACE FUNCTION nleast
      2    (p_n        IN NUMBER,
      3       p_nums        IN VARCHAR2)
      4    RETURN           NUMBER
      5  AS
      6    v_nleast      NUMBER;
      7  BEGIN
      8    SELECT DISTINCT column_value
      9    INTO   v_nleast
    10    FROM   (SELECT column_value,
    11                  DENSE_RANK () OVER (ORDER BY column_value) AS num_rk
    12              FROM   (select *
    13                   from   table (CAST (str2tbl (p_nums) AS mytabletype)))
    14             WHERE   column_value IS NOT NULL)
    15    WHERE  num_rk = p_n;
    16    RETURN v_nleast;
    17  EXCEPTION
    18    WHEN OTHERS THEN RETURN NULL;
    19  END nleast;
    20  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- query:
    scott@ORA92> SELECT col1, col2, col3,
      2           LEAST (col1, col2, col3) AS the_least,
      3           nleast (1, col1 || ',' || col2 || ',' || col3) AS first_least,
      4           nleast (2, col1 || ',' || col2 || ',' || col3) AS second_least,
      5           nleast (3, col1 || ',' || col2 || ',' || col3) AS third_least,
      6           nleast (4, col1 || ',' || col2 || ',' || col3) AS fourth_least
      7  FROM   your_table
      8  /
          COL1       COL2       COL3  THE_LEAST FIRST_LEAST SECOND_LEAST THIRD_LEAST FOURTH_LEAST
             1          2          3          1           1            2           3
             4          6          5          4           4            5           6
             8          7          9          7           7            8           9
            11         12         10         10          10           11          12
            15         13         14         13          13           14          15
            18         17         16         16          16           17          18
    6 rows selected.

Maybe you are looking for

  • Tecra S1 video out does not work

    Hi, I tried to connect my TS1 via cinch to a beamer. Unfortunately because of other reasons I can not use VGA. However I do not get any signal at all. I tried nearly everything. I installed Windows XP with Toshiba Recovery CDs again, but it does not

  • Incorrect PDF output after Bursting an Oracle 9i Report

    I have created a report for distribution. It is a single query based on several tables. I have 3 repeating frames -1 for the Budget Holder, then the cost centres for the Budget Holder, and then the nominal account for each of the cost centres. I remo

  • 1.83 Ghz Refurb

    Although I have been a Mac convert for over a year, I just recently discovered these discussions. My question is this: after 3 years of extremely reliable use, I am ready to retire my Sony VAIO notebook. (As a sidenote, it also ran hot enough to sear

  • Acrobat XI download issues

    How long is it suppose to take to download the Acrobat XI trial?  My laptop says 3 hours !  Also, how long is the trial period?

  • Screen capture of HP8562A using GPIB-PCMCIA card

    Hi, does anyone know if there is a way to do a s creen capture of an HP8562A spectrum analyzer using the GPIB-PCMCIA card? In the programming manual I can only find how to print/plot the screen, is there a way to save the screen in a file? thanks!