latest record new

  • this is my query

     

    select  PREM_ID, CHAR_TYPE_CD, CHAR_VAL, EFFDT, ADHOC_CHAR_VAL

    from CI_PREM_CHAR

    WHERE CHAR_TYPE_CD = 'UNITS'

    AND prem_id = '1589612791';

    i have attached the output : capture

     

    However i want the latest record only i.e

    PREM_ID: 1589612791

    CHAR_TYPE_CD : UNITS

    EFFDT : 13-JAN-18

    ADHOC_CHAR_VAL :40

     

    Please suggest

     

     

     

     

    Attachments:
    You must be logged in to view attached files.
  • Put TOP 1 after SELECT, and ORDER BY EFFDT DESC at the end of your query.

    John

  • hi jhon it is still giving error this is the query

    select  TOP 1 PREM_ID, CHAR_TYPE_CD, CHAR_VAL, EFFDT, ADHOC_CHAR_VAL

    from CI_PREM_CHAR

    WHERE CHAR_TYPE_CD = 'UNITS'

    AND prem_id = '1589612791'

    ORDER BY EFFDT DESC ;

    ERROR

    ORA-00923: FROM keyword not found where expected

    00923. 00000 -  "FROM keyword not found where expected"

    *Cause:

    *Action:

    Error at Line: 1 Column: 13

     

  • hi jhon it is still giving error this is the query

    select  TOP 1 PREM_ID, CHAR_TYPE_CD, CHAR_VAL, EFFDT, ADHOC_CHAR_VAL

    from CI_PREM_CHAR

    WHERE CHAR_TYPE_CD = 'UNITS'

    AND prem_id = '1589612791'

    ORDER BY EFFDT DESC ;

    ERROR

    ORA-00923: FROM keyword not found where expected

    00923. 00000 -  "FROM keyword not found where expected"

    *Cause:

    *Action:

    Error at Line: 1 Column: 13

  • This is a SQL Server forum.  Maybe someone here will know why that's not valid syntax in Oracle, but you'd probably be better off posting your question on an Oracle forum.

    John

  • Take a look at the row_number() function, there is plenty out there on the web for "ORACLE TOP N" as a search term in your favourite search engine queries which will show you how to do this

  • select  PREM_ID, CHAR_TYPE https://audacity.onl/_CD, CHAR_VAL  https://origin.onl/ https://mails.tips/temp-mail/

    • This reply was modified 4 years, 11 months ago by  HATYRA.
    • This reply was modified 4 years, 11 months ago by  HATYRA.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply