Query to get combinations of column values

-- Input Data
with t as (select 'H' as symbol, 1 as id from dual union all
          select 'H' as symbol, 2 as id from dual union all
          select 'H' as symbol, 3 as id from dual union all
          select 'H' as symbol, 4 as id from dual
,s as (select 'L' as symbol, 1 as id from dual union all
          select 'L' as symbol, 2 as id from dual union all
          select 'L' as symbol, 3 as id from dual union all
          select 'L' as symbol, 4 as id from dual
--select * from t,s
[pre]
-- Required output is four columns with the below values. The column headings are the ids from the original query. Therefore I suspect the solution would have some sort of crosstab..
id1---id2---id3---id4
HHHH     
HHHL          
HHLH     
HHLL                    
HLHH     
HLHL          
HLLH     
HLLL     
LHHH     
LHHL          
LHLH     
LHLL                    
LLHH     
LLHL          
LLLH     
LLLL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

select REPLACE(sys_connect_by_path(symbol,'-'),'-','' ) "id1---id2---id3---id4"
from (select*from t union all
select*from s)
where connect_by_isleaf = 1
start with id=1
connect by prior ID=ID-1
ORDER BY 1
I THINK U WANT THIS ........
select substr(regexp_substr(scbp, '-[^-]*', 1, 1),2) as ID1,
substr(regexp_substr(scbp, '-[^-]*', 1, 2),2) as ID2,
substr(regexp_substr(scbp, '-[^-]*', 1, 3),2) as ID3,
substr(regexp_substr(scbp, '-[^-]*', 1, 4),2) as ID4
from (
select sys_connect_by_path(symbol, '-') scbp
from (select*from t union all
select*from s)
where connect_by_isleaf = 1
start with id=1
connect by prior ID=ID-1
Edited by: user12108669 on Nov 12, 2009 9:42 PM
Edited by: user12108669 on Nov 12, 2009 9:43 PM

Similar Messages

  • Query to delete row where column value contains alphabets

    Hi,
    Could anyone please help me to get this query work.
    Query to delete row where column value contains alphabets.
    DELETE  FROM BIN_ITEM WHERE order_nmb LIKE '%[A-Z]%' || LIKE '%[a-z]%'
    Thanks and Regards,
    Deekay.

    RaminHashimzadeh wrote:
    SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
    Ramin Hashimzade
    But that won't reject strings like 'gfgG%dgh' which aren't pure alphabetic.
    Try:
    with test_data as (
    select 'ghTYJYEhdfe' str from dual
    union
    select 'dfF5ssd' from dual
    union
    select 'rgth*dgheh' from dual
    union
    select 'ggf{' from dual
    union
    select 'rwhrhrh' from dual
    select  *
    from test_data
    where regexp_instr(str,'[^[:alpha:]]')=0;

  • [Oracle 8i] Query for N rows by column value?

    I was just wondering if what I want to do is possible within my query (rather than programmatically)...
    I want to return the N most recent records for each unique value in a particular column.
    Here's a sample table:
    CREATE TABLE     orders
    (     order_no     numeric(10)
         part_no          varchar(5)
         close_date     date
         order_qty     numeric(10)
         scrap_qty     numeric(10)
         CONSTRAINT order_pk PRIMARY KEY (order_no)
    );And some sample data....
    INSERT INTO     orders     VALUES
    (0000012345,'ABC-1',TO_DATE('01-01-2010','mm-dd-yyyy'),10,1);
    INSERT INTO     orders     VALUES
    (0000013498,'ABC-1',TO_DATE('01-05-2010','mm-dd-yyyy'),12,2);
    INSERT INTO     orders     VALUES
    (0000033452,'ABC-1',TO_DATE('01-10-2010','mm-dd-yyyy'),5,0);
    INSERT INTO     orders     VALUES
    (0000001468,'ABC-1',TO_DATE('01-15-2010','mm-dd-yyyy'),15,1);
    INSERT INTO     orders     VALUES
    (0000022349,'BR723',TO_DATE('01-03-2010','mm-dd-yyyy'),8,1);
    INSERT INTO     orders     VALUES
    (0000069581,'BR723',TO_DATE('01-05-2010','mm-dd-yyyy'),5,0);
    INSERT INTO     orders     VALUES
    (0000436721,'BR723',TO_DATE('01-10-2010','mm-dd-yyyy'),14,1);
    INSERT INTO     orders     VALUES
    (0000213446,'A5001',TO_DATE('01-06-2010','mm-dd-yyyy'),5,1);
    INSERT INTO     orders     VALUES
    (0000327987,'A5001',TO_DATE('01-08-2010','mm-dd-yyyy'),5,0);
    INSERT INTO     orders     VALUES
    (0000041353,'A5001',TO_DATE('01-14-2010','mm-dd-yyyy'),12,1);
    INSERT INTO     orders     VALUES
    (0000011241,'A5001',TO_DATE('01-15-2010','mm-dd-yyyy'),5,1);In this example, what I want to return are the 2 most recent orders (by close_date) for each part number.
    Here is a table with the results I want to get, based on the scenario above:
    order_no     part_no          close_date     order_qty     scrap_qty
    0000001468     'ABC-1'          '01-15-2010'     15          1
    0000033452     'ABC-1'          '01-10-2010'     5          0
    0000436721     'BR723'          '01-10-2010'     14          1
    0000069581     'BR723'          '01-05-2010'     5          0
    0000011241     'A5001'          '01-15-2010'     5          1
    0000041353     'A5001'          '01-14-2010'     12          1Is it possible to write a query to get these results, or am I going to have to query for all available data, and find the 2 most recent rows programmatically?
    Thanks in advance!

    Hi,
    user11033437 wrote:
    I'm going to test that out right now. I think if it works, I may need to use dense_rank() rather than rank(), because it is possible that two orders for the same part number could have the same close date, and according to what I've looked up on the rank() and dense_rank() functions, rank() can give non-consecutive results if the values are the same.What's wrong with non-consecutive values?
    Use RANK, DENSE_RANK or ROW_NUMBER depending on what you want.
    For example; say a certain part has been ordered 8 times:
    3 times with close_date January 29, 2010 (all at exactly the same time),
    4 times with close_date January 28, 2010 (all at exactly the same time), and
    1 time with close_date January 27, 2010.
    If you ask for the last 2 rows:
    RANK will give you the 3 rows from January 29. (All 3 have an equal claim to being in the top 2.)
    DENSE_RANK will give you the 7 rows from January 28-29 (the last two values , regardless of how many rows have them).
    ROW_NUMBER will give you 2 rows from January 29. (Which 2? It's arbitrary unless you add a tie-breaker to the ORDER BY clause.)
    All these functions are available in Oracle 8.1.

  • Getting an extra column value in a group by expression

    I have the following table-
    CREATE TABLE dummy_data (
    ID number NOT NULL , mark number not null
    ,test_Timestamp timestamp NOT NULL
    insert into dummy_data (id,mark,test_TimeStamp) values (1,12,'08-MAR-10 09.43.30.922000000');
    insert into dummy_data (id,mark,test_TimeStamp) values (2,12,'08-MAR-10 09.46.30.922000000');
    insert into dummy_data (id,mark,test_TimeStamp) values (3,16,'08-MAR-10 09.23.30.922000000');
    insert into dummy_data (id,mark,test_TimeStamp) values (4,18,'08-MAR-10 09.26.30.922000000');
    insert into dummy_data (id,mark,test_TimeStamp) values (5,20,'08-MAR-10 09.13.30.922000000');
    insert into dummy_data (id,mark,test_TimeStamp) values (6,22,'08-MAR-10 09.12.30.922000000');
    select TO_CHAR(TO_DATE (ceil(to_number(to_char(test_Timestamp, 'yyyymmddhh24mi'))/5)*5,'yyyymmddhh24mi'),'yyyy-mm-dd hh24:mi') as ts , id
    from dummy_data
    group by TO_CHAR(TO_DATE (ceil(to_number(to_char(test_Timestamp, 'yyyymmddhh24mi'))/5)*5,'yyyymmddhh24mi'),'yyyy-mm-dd hh24:mi'), id;
    I use the below query to get the id grouped by 5 minutes interval.
    Now I also need to get the Mark associated with the id, in a single query. Is there a way to get it ?
    Thanks
    _Pete                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I am sorry should have given little more details on my request and I am not sure even if it possible to do that in sql.
    Though I am grouping by 5 minute interval. If the mark is there for the last one hour, show that entry only once.
    In other words, in my example
    Take this to samples (see same mark)
    insert into dummy_data (id,mark,test_TimeStamp) values (6,12,'08-MAR-10 09.12.30.922000000');
    insert into dummy_data (id,mark,test_TimeStamp) values (2,12,'08-MAR-10 09.46.30.922000000');
    When you group by id, you will get separate values for 9:10-9:15 5 minute interval and another one for 9:45-9:50 interval.
    What I want is if the mark has already appeared in that one hour interval, I don't want it to be repeated.
    Thanks
    _Pete                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Content Search Query Builder - filtering for custom column value

    I want to use a CSWP to display certain pages in a slideshow format on a site.  However, to filter them in a preferred manner, the pages library has a custom column "Spotlight" which is a Boolean type (e.g. yes/no).
    In my "Build Your Query" configuration page, I have added a keyword filter "SpotlightOWSBOOL=Yes" as the criteria to display my results.  This is not working, despite the fact that I currently have pages flagged as "Spotlight"
    in this library. 
    My question is - how can I achieve this result of displaying only pages with a custom column value "Spotlight" as "Yes"?

    Hi Owen,
    Could you capture a screenshot about your Crawled Property for your list column "Spotlight"?  Is it name "SpotlightOWSBOOL"?
    If your library column name is "Spotlight", you can create a custom
    Manged Property (e.g. create name as SpotlightMangedProperty)to map the
    Crawled Propery (e.g. may ows_spotlight, or ows_SpotlightOWSBOOL?) genegrated by list column "Spotlight", then start a full crawl.
    Then you can add the keyword filter like below in "Build Your Query" dialog of CSWP web part, then check if the correct items are filtered.
    SpotlightMangedProperty:"yes"
    If the above value "yes" doesn't work, please also try
    SpotlightMangedProperty:"True", or try SpotlightMangedProperty:1
    More information about this topic you can read is below.
    https://technet.microsoft.com/en-us/library/jj219667.aspx#proc2
    https://msdn.microsoft.com/en-us/library/office/ee558911.aspx#kql_property_restriction_queries
    Thanks
    Daniel Yang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Query to get parameter name and value after ran the conccurent program

    Hi All,
    Query to get the parameter name and value for completed concurrent program using the request id. can any one help me in this regard.
    Thanks,
    Red.

    Red,
    I have tried the same query and it works properly here.
    I have submitted "Purge Signon Audit data" concurrent program with "Audit Date" parameter set to 01-06-2009, and here is the query output:
    SQL> select request_id, phase_code, status_code,
    argument_text, argument1
    from fnd_concurrent_requests
    where request_id = '739664';
    REQUEST_ID P S ARGUMENT_TEXT        ARGUMENT1
        739664 C C 2009/06/01 00:00:00  2009/06/01 00:00:00Regards,
    Hussein

  • Is there a way to get notification when column value is updated ?

    Is there a way to check when a column value has been updated?
    Example: "Project Start Date" has changed from March to June. RMS report will be sent via iBot to notify users.

    Find out if (in your country) there is a landline phone with a "ring" light on it. (In some countries, it's possible to buy a phone which is easily plugged in at home by the user.)

  • Combine 2 Column Values in One Prompt - - - - Urgent

    Hi Experts,
    I'm Using Obiee10g.
    I have a requirement where i need to create a prompt (based on 2 column values)
    Example: Name of Prompt (Search Agency) it has following values
    Agency Type1
    Agency Type2
    Agency Subtype1
    Agency Subtype2
    Agency Type1, Agency Type2 are Major Types - Which comes from Column: Agency Type
    Agency Subtype1, Agency Subtype2 are subtypes - Which comes from Column: Agency Subtype
    I took a dummy column from subject area. Converted the Prompt to Sql Results and wrote the following condition.
    Select Agency_type from Agency where Agency Type in (Agency Type1, Agency Type2)
    union
    Select Agency_subtype from Agency Where Agency subtype in (Agency Subtype1, Agency Subtype2)
    Now, My Prompt is showing correct values.
    And, My Report has following columns: Agency Id, Agency Name, Agency Type, Agency Subtype (Agency Type is prompted or Agency Subtype is prompted)
    Now, My Prompt and Report not reflects properly as i need to use multi select for prompts
    If, i'm using drop down and storing the values in presentation variable and saying that
    Agency Type = pv1 (Presen. variable1) default a
    or
    Agency Subtype = pv1 (presen. variable1) default a
    Then, it works.
    But, I need Multi select prompt. And, i cannot use p.v for multi select.
    How to acheive the above functionality.
    Experts, Please guide me.....

    If I'm Using And Condition it fails.
    Because,
    Say I have Types as - Type1, Type2
    Say I have Subtypes as - Subtype1, subtype2, subtype3
    Type table
    Type1, subtype1
    Type1, subtype2
    Type2, Subtype3
    Now, if select prompt1 ( Prompt1 is prompted -> Type1 is prompted) ----> My report reflects for type1
    if I Select prompt2 (Prompt2 is prompted -> Subtype3 is prompted) -----> My Report reflects for subtype3
    If i use here And ----> it fails ( Type = Type1 and Subtype = Subtype3)
    It should be Or ----> (Type = Type1 or Subtype = Subtype3) ----> this passes only when i select both values. But, my requirement is it should pass for even one selection.
    It can be done for drill down and pres. variable. But, my requ. is multiselect.

  • How to get all the column values from a table source

    Hi,
    I have created one table source on a employee table and some customized attributes using global settings>search attributes.
    Now these customized attributes mapped with the table columns through attribute mapping from the sorce tab.
    Using doOracleSearch method i passed last parameter i.e. Integer array of customized attributes.
    After execution of doOracleSearch method i am getting the results but customized attributes are not coming.
    getCustomAttributes method returns null instead of some values.
    Please refer following code for more info:
    Integer[] fetchAttr=new Integer[2];
    fetchAttr[0]=new Integer(137);
    fetchAttr[1]=new Integer(138);
    result =
    stub.doOracleSearch("BTM",
    new Integer(1),
    new Integer(10),
    Boolean.TRUE,
    Boolean.TRUE,
    group,
    "en",
    "en",
    Boolean.TRUE,
    null,
    null,
    fetchAttr);
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    System.out.println("Title : " + resElements[0].getTitle());
    System.out.println("Snippet : " + resElements[0].getSnippet());
    System.out.println("URL : " + resElements[0].getUrl());
    System.out.println("non default : " + resElements[0].getCustomAttributes()); // it returns null here
    }

    Confirm the attributes you are asking SES for match those on the data source being searched. One thing to try is to simply tell SES to return all custom attributes for your search. Here is a snippet to build a list of all attribute IDs and pass them to your search...
    // Create and set SOAP URL
    OracleSearchService searchService = new OracleSearchService();
    searchService.setSoapURL("http://myserver:7777/search/query/OracleSearch");
    // Set attributes to fetch (all)
    Attribute[] attributesAll = searchService.getAllAttributes("en");
    ArrayList<Integer> attributeIds = new ArrayList<Integer>();
    for(Attribute a: attributesAll)
    attributeIds.add(a.getId());
    Integer attributeIdArrayAll[] = new Integer[attributeIds.size()];
    attributeIdArrayAll = attributeIds.toArray(attributeIdArrayAll);      
    // Query
    OracleSearchResult result = searchService.doOracleSearch("some text", ..........[other params], attributeIdArrayAll);
    // Print out results
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    // Get document
    ResultElement doc = resElements;
    // Print Title
    System.out.println("Title: " + doc.getTitle());
    // Print custom attributes
    CustomAttribute[] attributes = doc.getCustomAttributes();
    for(int j = 0; j < attributes.length; j++)
    CustomAttribute attr = attributes[j];
         System.out.println("[Custom Attribute] " + attr.getName() + ": " + attr.getValue());
    Hope this helps.

  • How to write this query to filter combination of few values

    Hi,
    I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
    columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
    HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
    I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
    OR
    if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
    How to write this query?
    Regards

    Hi,
    I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
    CHILD_ID
           3
           4? If so, here's one way to get them:
    WITH     all_vacc_ids     AS
         SELECT     c.child_id
         ,     c.vacc_id          AS child_vacc_id
         ,     v.vacc_id
         ,     COUNT ( CASE
                             WHEN  c.vacc_id = 'HEXA'
                       THEN  1
                         END
                    )       OVER ( PARTITION BY  c.child_id
                                       )    AS hexa_itself
         FROM          vacc   v
         LEFT OUTER JOIN     chimm  c     PARTITION BY (c.child_id)
                          ON     c.vacc_id     = v.vacc_id
         WHERE   v.vacc_desc       = 'HEXA'     -- See note below
    SELECT       child_id
    FROM       all_vacc_ids
    WHERE       child_vacc_id     IS NULL
      AND       vacc_id     != 'HEXA'
      AND       hexa_itself     = 0
    GROUP BY  child_id
    rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
    You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher).

  • Getting last year column value from a single table

    I am having the following columns in my table
    BRANCH_CD
    YYMM
    VNDR#
    VGROUP#
    SALES_TRGT_AMT
    SALES_ACTL_AMT
    CUM_TRGT_AMT
    CUM_ACTL_AMT
    i need to get sales_actl_amt from this year and sales_actl_amt from last year from a single table
    pls help
    thank you
    Edited by: 960991 on Nov 19, 2012 11:13 PM

    Hi ashish,
    but i can't use unions in my reports.
    once view my query :
    select t.branch_cd,b.branch_e_name,t.vndr#,v.vndr_name,
    sum(nvl(t.sales_actl_amt,0)) sales_actl_amt
    from inv_sales_trgt_val t,branches b,vendor v where
    t.branch_cd=b.branch_cd and
    t.vndr#=v.vndr# and
    (t.yymm between :fiscal_month and :fiscal_month2) and
    (:fiscal_month<>trunc(:fiscal_month2,-2)) and :fiscal_month2<>trunc(:fiscal_month2,-2)) and t.branch_cd between :from_branch and to_branch and
    t.vndr# between :from_vndr and :to_vndr
    group by t.vndr#,v.vndr_name,t.branch_cd,b.branch_e_name
    order by t.vndr#,t.branch_cd;
    how can i get last year sales_actl_amt .

  • Query for getting combination of data

    hi all,
    i am using db10g.
    i have a table of fields a_company,a_code,a_name,a_port,a_t_port,a_rate,a_volume
    i have a records like
    MM,AA,A-NAME,EFG,EFGH,100,20
    MM,AA,A-NAME,EFG,EFGH,200,10
    MM,BB,B-NAME,HIJ,HIJK,100,20
    MM,BB,B-NAME,HIJ,HIJK,200,30
    MM,CC,C-NAME,DEF,DEFG,500,20i have to select all columns but the fields if below below combination repeates(having more than 1 combination)
    a_company,a_code,a_port,a_t_port
    how can form a query?
    in other words i am expecting the result like below among above said input.
    MM,AA,A-NAME,EFG,EFGH,100,20
    MM,AA,A-NAME,EFG,EFGH,200,10
    MM,BB,B-NAME,HIJ,HIJK,100,20
    MM,BB,B-NAME,HIJ,HIJK,200,30Thanks..

    With only one table scan:
    SQL> create table a_table (a_company,a_code,a_name,a_port,a_t_port,a_rate,a_volume)
      2  as
      3  select 'MM','AA','A-NAME','EFG','EFGH',100,20 from dual union all
      4  select 'MM','AA','A-NAME','EFG','EFGH',200,10 from dual union all
      5  select 'MM','BB','B-NAME','HIJ','HIJK',100,20 from dual union all
      6  select 'MM','BB','B-NAME','HIJ','HIJK',200,30 from dual union all
      7  select 'MM','CC','C-NAME','DEF','DEFG',500,20 from dual
      8  /
    Table created.
    SQL> exec dbms_stats.gather_table_stats(user,'a_table')
    PL/SQL procedure successfully completed.
    SQL> set autotrace on explain
    SQL> select a_company
      2       , a_code
      3       , a_name
      4       , a_port
      5       , a_t_port
      6       , a_rate
      7       , a_volume
      8    from ( select a.a_company
      9                , a.a_code
    10                , a.a_name
    11                , a.a_port
    12                , a.a_t_port
    13                , a.a_rate
    14                , a.a_volume
    15                , count(*) over (partition by a_company,a_code,a_port,a_t_port) cnt
    16             from a_table a
    17         )
    18   where cnt > 1
    19  /
    A_ A_ A_NAME A_P A_T_     A_RATE   A_VOLUME
    MM AA A-NAME EFG EFGH        100         20
    MM AA A-NAME EFG EFGH        200         10
    MM BB B-NAME HIJ HIJK        100         20
    MM BB B-NAME HIJ HIJK        200         30
    4 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=5 Bytes=330)
       1    0   VIEW (Cost=4 Card=5 Bytes=330)
       2    1     WINDOW (SORT) (Cost=4 Card=5 Bytes=140)
       3    2       TABLE ACCESS (FULL) OF 'A_TABLE' (Cost=2 Card=5 Bytes=140)Regards,
    Rob.

  • UPDATE_ROW_CONFLICT error, get the details (columns, values)

    Hi,
    I am getting the following error:
    Error :Number of conflicts while synchronizing: 1 SyncResolver.UPDATE_ROW_CONFLICT row 0 attempt to update a row that has been updated or deleted by another user
    has anybody an idea how to get more information about the conflic?
    In what column is the conflic ? The values ?
    regards,
    Andorn

    Hi,
    Please go through the tutorial titled "Performing Inserts, Updates, and Deletes" which is available at: http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/inserts_updates_deletes.html
    Also, go through the below forum threads:
    http://swforum.sun.com/jive/thread.jspa?threadID=95174&tstart=15
    http://forum.sun.com/jive/thread.jspa?forumID=123&threadID=65088
    Hope this helps.
    RK

  • Query to get row with max values for distinct

    I have a table test with ID, ADID, MTMST columns.
    ID     ----ADID----     MTMST
    1     ----100----     24-MAR-12 08.17.09.000000 PM
    1     ----101----     24-MAR-12 08.18.15.000000 PM
    1     ----102----     24-MAR-12 08.18.56.000000 PM
    2     ----103----     24-MAR-12 08.19.21.000000 PM
    2     ----104----     24-MAR-12 08.19.36.000000 PM
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    3     ----99----      22-MAR-12 09.48.22.000000 PM
    I need the rows with max ADID for each ID.
    I used the following query but it provided max ADID of the table but not the distinct ID
    select * from test where ADID in (select max(ADID) from test where id in (select distinct(id) from test where mtmst > sysdate -1))
    Result:*
    ID     ----ADID----     MTMST
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    Expected result:*
    ID     ----ADID----     MTMST
    1     ----102----     24-MAR-12 08.18.56.000000 PM
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    Thanks,
    Dheepan
    Edited by: Dheepan on Mar 24, 2012 9:53 AM

    select id, adid, mtmst from test where (id, adid) in (select id, max(adid) from test group by id) and MTMST>sysdate-1
    is the answer.

  • Query to get Datatype of columns

    Hi Experts,
    i need the query or any view that can tell me all the tables that have a specific data type column let say CLOB. so is there any sql statement that can full fill this requirement.
    regards,

    The rdbms dictionary views are defined in the Oracle version# Reference manual.
    Try looking at dba_tab_columns, which lists all the columns for the tables and views defined in the database.
    HTH -- Mark D Powell --

Maybe you are looking for