Distinct Key word in sql

Hello Good folks,
I have a simple oracle view (that fetches data from mutiple tables).
There are approximately 7 columns in the view. I want the view to get unique data based on only 2 columns (not all 7 columns).
View looks like this now.
select distinct cusip, calendar-date,price,aa,bb,cc,dd
from view_aa
order by cusip.
view fetches Data like this.
cusip, calendar-date, price, aa, bb, cc, dd
01 Jan-01-2009 1000 10 12 8 5
01 Jan-01-2009 2000 10 11 8 5
02 Fed-22-2009 3000 11 12 6 4
But I want the view to get the following data only
cusip, calendar-date, price, aa, bb, cc, dd
01 Jan-01-2009 1000 10 12 8 5
02 Fed-22-2009 3000 11 12 6 4
Any advise/suggestions on how to get non-duplicate data?
Help much appreciated.
thanks
nath

Hi, Nath,
So you only want one row for every cuspid and calendar_date.
Is that one row
(a) some kind of combination (that is, an aggregate ) of all of the rows with that cuspid and calendar_date (if so, what?), or is it
(b) one of those rows, exactly as it is in the table? If so, which one?
I assume you want (b), where the row chosen is the one with the lowest price. If there are two (or more) rows with the same lowest price then, from among them, the one with the highest aa will be chosen. If there is still a tie, one of those rows will be chosen arbitrarily.
WITH     got_rnum     AS
     SELECT     cusip, calendar_date, price, aa, bb, cc, dd
     ,     ROW_NUMBER () OVER ( PARTITION BY  cusip
                         ,             calendar_date
                         ORDER BY        price
                         ,             aa          DESC
                       )     AS rnum
     FROM     view_aa
--     WHERE     ...     -- Any filtering goes here
SELECT     cusip, calendar_date, price, aa, bb, cc, dd
FROM     got_rnum
WHERE     rnum     = 1
;This is called a Top-N Query because you are choosing N rows (N=1 in this case) from the top of an ordered list.

Similar Messages

  • Creating Materialized View with the Distinct key word

    Hi
    I need help to create Materialized View with the Distinct key word.
    my query is
    select distinct col1, col2 from t1;
    is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.

    hi
    check out this link
    http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
    hope this helps
    CHeers

  • Missing Key word?

    What key word am I missing from here?
    SQL> alter database recover datafile '/xxx.dbf' auto;
    alter database recover datafile '/xxx.dbf' auto
    ERROR at line 1:
    ORA-00905: missing keyword

    Hi Friend,
    That's wrong too. I just got the right answer.
    recover datafile /xxx.dbf';

  • Query to list all the key words

    Hi all,
    Could anyone tell me the query to list out all the keywords that are used in Oracle.
    That will be very helpful to me
    Thanks

    I created a new user and just gave him CREATE SESSION privilege. He has nothing else
    SQL> connect sys/*****@****** as sysdba
    Connected.
    SQL> create user reserve_word_test identified by password
      2  /
    User created.
    SQL> grant create session to reserve_word_test
      2  /
    Grant succeeded.Now i connect as that user and query V$RESERVE_WORDS
    SQL> connect reserve_word_test/password@******
    Connected.
    SQL> SELECT * FROM V$RESERVED_WORDS
      2  /
    SELECT * FROM V$RESERVED_WORDS
    ERROR at line 1:
    ORA-00942: table or view does not existAs the user does not have access to the data dictionary table its erroring out.
    But see this
    SQL> help reserved words
    RESERVED WORDS (PL/SQL)
    PL/SQL Reserved Words have special meaning in PL/SQL, and may not be used
    for identifier names (unless enclosed in "quotes").
    An asterisk (*) indicates words are also SQL Reserved Words.
    ALL*            DESC*           JAVA            PACKAGE         SUBTYPE
    ALTER*          DISTINCT*       LEVEL*          PARTITION       SUCCESSFUL*
    AND*            DO              LIKE*           PCTFREE*        SUM
    ANY*            DROP*           LIMITED         PLS_INTEGER     SYNONYM*
    ARRAY           ELSE*           LOCK*           POSITIVE        SYSDATE*
    AS*             ELSIF           LONG*           POSITIVEN       TABLE*
    ASC*            END             LOOP            PRAGMA          THEN*
    AT              EXCEPTION       MAX             PRIOR*          TIME
    AUTHID          EXCLUSIVE*      MIN             PRIVATE         TIMESTAMP
    AVG             EXECUTE         MINUS*          PROCEDURE       TIMEZONE_ABBR
    BEGIN           EXISTS*         MINUTE          PUBLIC*         TIMEZONE_HOUR
    BETWEEN*        EXIT            MLSLABEL*       RAISE           TIMEZONE_MINUTE
    BINARY_INTEGER  EXTENDS         MOD             RANGE           TIMEZONE_REGION
    BODY            EXTRACT         MODE*           RAW*            TO*
    BOOLEAN         FALSE           MONTH           REAL            TRIGGER*
    BULK            FETCH           NATURAL         RECORD          TRUE
    BY*             FLOAT*          NATURALN        REF             TYPE
    CHAR*           FOR*            NEW             RELEASE         UI
    CHAR_BASE       FORALL          NEXTVAL         RETURN          UNION*
    CHECK*          FROM*           NOCOPY          REVERSE         UNIQUE*
    CLOSE           FUNCTION        NOT*            ROLLBACK        UPDATE*
    CLUSTER*        GOTO            NOWAIT*         ROW*            USE
    COALESCE        GROUP*          NULL*           ROWID*          USER*
    COLLECT         HAVING*         NULLIF          ROWNUM*         VALIDATE*
    COMMENT*        HEAP            NUMBER*         ROWTYPE         VALUES*
    COMMIT          HOUR            NUMBER_BASE     SAVEPOINT       VARCHAR*
    COMPRESS*       IF              OCIROWID        SECOND          VARCHAR2*
    CONNECT*        IMMEDIATE*      OF*             SELECT*         VARIANCE
    CONSTANT        IN*             ON*             SEPERATE        VIEW*
    CREATE*         INDEX*          OPAQUE          SET*            WHEN
    CURRENT*        INDICATOR       OPEN            SHARE*          WHENEVER*
    CURRVAL         INSERT*         OPERATOR        SMALLINT*       WHERE*
    CURSOR          INTEGER*        OPTION*         SPACE           WHILE
    DATE*           INTERFACE       OR*             SQL             WITH*
    DAY             INTERSECT*      ORDER*          SQLCODE         WORK
    DECIMAL*        INTERVAL        ORGANIZATION    SQLERRM         WRITE
    DECLARE         INTO*           OTHERS          START*          YEAR
    DEFAULT*        IS*             OUT             STDDEV          ZONE
    DELETE*         ISOLATION
    RESERVED WORDS (SQL)
    SQL Reserved Words have special meaning in SQL, and may not be used for
    identifier names unless enclosed in "quotes".
    An asterisk (*) indicates words are also ANSI Reserved Words.
    Oracle prefixes implicitly generated schema object and subobject names
    with "SYS_". To avoid name resolution conflict, Oracle discourages you
    from prefixing your schema object and subobject names with "SYS_".
    ACCESS          DEFAULT*         INTEGER*        ONLINE          START
    ADD*            DELETE*          INTERSECT*      OPTION*         SUCCESSFUL
    ALL*            DESC*            INTO*           OR*             SYNONYM
    ALTER*          DISTINCT*        IS*             ORDER*          SYSDATE
    AND*            DROP*            LEVEL*          PCTFREE         TABLE*
    ANY*            ELSE*            LIKE*           PRIOR*          THEN*
    AS*             EXCLUSIVE        LOCK            PRIVILEGES*     TO*
    ASC*            EXISTS           LONG            PUBLIC*         TRIGGER
    AUDIT           FILE             MAXEXTENTS      RAW             UID
    BETWEEN*        FLOAT*           MINUS           RENAME          UNION*
    BY*             FOR*             MLSLABEL        RESOURCE        UNIQUE*
    CHAR*           FROM*            MODE            REVOKE*         UPDATE*
    CHECK*          GRANT*           MODIFY          ROW             USER*
    CLUSTER         GROUP*           NOAUDIT         ROWID           VALIDATE
    COLUMN          HAVING*          NOCOMPRESS      ROWNUM          VALUES*
    COMMENT         IDENTIFIED       NOT*            ROWS*           VARCHAR*
    COMPRESS        IMMEDIATE*       NOWAIT          SELECT*         VARCHAR2
    CONNECT*        IN*              NULL*           SESSION*        VIEW*
    CREATE*         INCREMENT        NUMBER          SET*            WHENEVER*
    CURRENT*        INDEX            OF*             SHARE           WHERE
    DATE*           INITIAL          OFFLINE         SIZE*           WITH*
    DECIMAL*        INSERT*          ON*             SMALLINT*
    SQL>If sql plus accesses the database then how its possible?

  • 3.0 EA3, Key-Words should not be translated at all.

    Hi all,
    at first my compliment to the dev team. The raptor is about to fledgeup ....
    A little hint (not a real problem):
    From the Schema Browser chose a table (mark it via mouse) and Drag it into the SQL area. A dialog box appears with radio buttons to pick up the action of your choise.
    In german the translation is a bit silly. Don't translate these texts here - it makes no sense.
    OK is: Insert = INSERT and update = UPDATE.
    But "Löschen"= DELETE is strange, and "Wählen" = SLECT is simply silly at all.
    To make a long story short, Key-Words should not be translated at all.
    Thank you!
    Andre

    Unfortunately, the custom style sheet "feature" is still horribly broken, even in the latest 3.0.3. Setting a file in the preferences still doesn't set the correct URI in the preferences (either that, or Safari still doesn't know how to use a Windows file path to locate the style sheet).
    I'm also encountering problems where Safari will crash when using an ad blocking custom stylesheet.
    Also, when having the custom stylesheet set, trying to use the "Inspect Element" feature will crash Safari.

  • How to use the distinct key in formula field in SAP Crystal Reports

    I want to use the distinct key in formula field in SAP Crystal reports.
    When i'm using it shows an error.
    Please suggest me....

    Hi,
    Use DistinctCount keyword directly for your calculation instead of count(distinct(....
    Alternatively, if you want to avoid duplicate records, under "File" > "Report Options" make the 'Select Distinct Records' as True.
    Thanks,
    Raghavendra

  • MBAM bitlocker-protected removable drives recovery keys saved on sql database not active directory

    Hi Guys
    I need help in saving bitlocker protected removable drives on the sql database instead of active directory .
    I have tried to play around with the policy and I am not winning , currently my GPO : Choose how bitlocker-protected removable drives can be recovered has only the allow data recovery agent chosen and I have left out all the AD DS option unticked
    Please point me in the right direction on how to achieve this , I want all my keys in a SQL database so the users can recover the keys themselves using the mbam helpdesk website

    Under client management, define your endpoint URLs. You can see the help and the description section for that particular policy. Copy and paste the URL removing the port number and replace the name of the Server with that of your MBAM Web server.
    Also, Disable or don't configure the policy "Choose how bitlocker protected removable Drives can
    be recovered".
    This will save your recovery keys to the MBAM DBs.
    Gaurav Ranjan

  • What is use of LOAD key word in ABAP-HR

    what is use of LOAD key word in ABAP-HR?

    Hi,
    LOAD keyword is used to load all the parameter values.
    Basic form
    LOAD REPORT prog PART part INTO itab.
    Variants
    1. LOAD REPORT prog PART 'HEAD' INTO itab.
    2. LOAD REPORT prog PART 'TRIG' INTO itab.
    3. LOAD REPORT prog PART 'CONT' INTO itab.
    4. LOAD REPORT prog PART 'DATA' INTO itab.
    5. LOAD REPORT prog PART 'DDNM' INTO itab.
    6. LOAD REPORT prog PART 'DATV' INTO itab.
    7. LOAD REPORT prog PART 'SELC' INTO itab.
    8. LOAD REPORT prog PART 'STOR' INTO itab.
    9. LOAD REPORT prog PART 'LITL' INTO itab.
    10. LOAD REPORT prog PART 'SYMB' INTO itab.
    11. LOAD REPORT prog PART 'LREF' INTO itab.
    12. LOAD REPORT prog PART 'SSCR' INTO itab.
    13. LOAD REPORT prog PART 'BASE' INTO itab.
    14. LOAD REPORT prog PART 'INIT' INTO itab.
    15. LOAD REPORT prog PART 'DATP' INTO itab.
    16. LOAD REPORT prog PART 'TXID' INTO itab.
    17. LOAD REPORT prog PART 'COMP' INTO itab.
    Effect
    Loads the specified part of the generated version of the program prog into the internal table itab (for analysis purposes only).
    The return code value is set as follows:
    SY-SUBRC = 0 The load for the program prog exists and is current.
    SY_SUBRC = 4 The load for the program prog does not exist.
    SY-SUBRC = 8 The load for the program prog exists, but is not current. In some cases, this SY-SUBRC may mean that the program load has been destroyed. You can resolve this by generating the program. With PART 'LREF' , SY-SUBRC = 8 means that the line reference table is incorrect for the program. With PART 'CONT' , it means that the reference part of the internal table is empty.
    itab has been filled only if SY-SUBRC = 0 .
    Reward points if useful.
    Regards,
    Sekhar

  • How to translate the key words in ABAp program from lower case to upper cas

    How to translate the key words in ABAp program from lower case to upper case?

    Hi Kittu,
    You need to set the Pretty Printer settings to achieve key words in ABAP program from lower case to upper case.
    Utilities -> Settings -> Pretty Printer (tab) -> Select third radio button.
    Thats all.
    <b>Reward points if this helps.
    Manish</b>

  • Help on web.xml file, what if the parameters contains key words ?

    Hi:
    I am just wondering what should I do if I want to include key words suchs
    as <param> in web.xml file for a servlet config.
    Example:
    <servlet>
    <servlet-name>testServlet</servlet-name>
    <parameter>
    <param-name>some name</param-name>
    <param-value>some value</param-value>
    </parameter>
    </servlet>
    What should I do if I want to repleace 'some value' with '</param-value>some
    value' and still to prevent the engine to terminate parsing the param-value
    at the fake ending? Is there a standard way in XML to distanguish that?
    (in URL format it can be replaced %xx for some chars).
    ie,
    <param-value> </param-value>some value</param-value>
    where the second </param-value> is the real ending.
    Thank you!
    Gang

    Hi!
    You can use "& lt ;" and "& gt ;" xml entities for that. Or wrap text element in <![CDATA[...]]> section.
    Regards,
    Ignat.

  • Is there a way to identify the key words being used for SEO when I'm visiting a web site?

    When I am on a web site, looking at a product for sale, is there an app or add on I can use to see what that site has for key words, meta tags etc? It would be helpful when adding products to my own site to see what works elsewhere.

    Do search engines even look at those anymore? URL, title and page content are what's relevant.
    * http://www.metatags.org/google_ignores_meta_tags_in_ranking
    In any case, you can look at the source code. Click the Firefox button, then Web Developer, then View Source. You can also press Ctrl+U.
    All 'SEO' add-ons:
    * https://addons.mozilla.org/firefox/search/?q=seo&sort=users

  • Apple should do something for the equipment stolen something like block and only activated by key words given to register the device on the apple's website

    Apple should do something for the equipment stolen something like block it(them) and only activated by key words given to register the device on the apple's website

    Tell Apple:
    http://www.apple.com/feedback
    Doubtful that this would happen.  Privacy laws would likely be tested with this.
    No manufacturer does this.

  • LEVEL key word in Oracle 9.2.0.1.0 & Oracle 9.2.0.7.0

    Hi experts,
    I'm using a Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production in my development environment and
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production in production environment.
    I use a query with a LEVEL key word and it works fine in the development environment and gives an error in the production environment. When I remove the LEVEL key word it works fine in the production also.
    Was there a change which happen to LEVEL key word in these releases ???

    PrasadDe wrote:
    Was there a change which happen to LEVEL key word in these releases ???Probably. Who can tell. Those are both unsupported versions of the database.
    Why not upgrade to something that's supported and we know works.

  • What are all the key words are not recommented in User Exit or Enhancement

    Dear Experts,
    Can any of one tell me, what are all the key words not recommended to use any of the User exit or Enhancement spots?
    Regards,
    Mohana
    Moderator message: please search for available information/documentation.
    Edited by: Thomas Zloch on Feb 22, 2011 4:10 PM

    No Icon:Visitor
    Student
    Honor Student
    Top Student
    Tutor
    Intern
    Teacher
    Grad Student
    Master’s Graduate
    PhD Student
    Associate Professor
    Professor
    Distinguished Professor
    Regents Professor
    Associate Dean
    Dean
    Provost
    FONDA X. COX, PhD

  • How to get the system key in PL/SQL?

    Hi All,
    Is there a way to get master system key from PL/SQL?
    Thanks

    I am not sure about how to change SERVICE_NAME in PL/SQL Developer (if at all it can be done in that ), but you will have to change the SERVICE_NAME in the TNSNAMES.ORA file.
    1. Locate the entry for PLSExtProc in the file tnsnames.ora at:
    $ORACLE_HOME/network/admin/tnsnames.ora
    2. Change the SERVICE_NAME = ORCL
    3. Save and reconnect
    Aalap Sharma :)

Maybe you are looking for

  • Why can i not open itunes?

    I cannot open itunes on my windows laptop. Says something about newer version of itunes.library.itl. If i uninstall/reinstall, what happens to my existing library (FULL of music)?? Please help!!

  • Problem accessing VARRAY OF VARCHAR in 9i, but working in 8i

    The following code (modified sample ArrayExample.java for VARRAY OF VARCHAR) produces different results on a 8.1.7 and 9.0.1 database. The standard way of accessing the members of an array of strings in the database: ARRAY array = ((OracleResultSet)r

  • Linked documents in printed documentation

    Hi. I have a Robohelp project that contains links to Word docs. I know while generating the help project, Robohelp copies the Word docs into the help folder. So, my question is: Is there a way, when generating printed documentation, for Robohelp to i

  • Java:comp/env namespace is only available from within a J2EE component

    Can someone help me to explain and resolve the Exception? The Exception is like below: javax.naming.NamingException: java:comp/env namespace is only available from within a J2EE component

  • Unable to start IDCAdmin

    Hi, I have set up a new CMS server on Linux machine. While I am trying to start the IDCAdmin, I am getting following error. I have tried starting it through content Server in web browser as well as through console, by going to the directory "Oracle/u