Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Help in Query - Oracle

Help in Query - Oracle

Scheduled Pinned Locked Moved Database
databaseoraclehelpannouncement
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aaraaayen
    wrote on last edited by
    #1

    Hi Friends, I need help in the following query. SELECT A.BILL, A.BILLER, A.VERSION_NO, A.CODE, A.NAME,A.SEGMENT_CODE, A.COMMENT,B.BILL AS BILL, B.BILLER AS DW_BILLER, B.MCN AS DW_MCN, B.SO AS DW_SO, B.BG AS DW_BG, B.CODE AS DW_CODE, B.NAME AS DW_NAME,B.SEGMENT_CODE AS DW_SEGMENT_CODE FROM WEB_REF A, WEB_CUST B WHERE A.BILL=B.BILL AND A.BILLER=B.BILLER ORDER BY A.BILL The above query is working fine. and o/p like below: A3 3A 3 A3 3A 2 A3 3A 1 But now requirement is that, the table A consists VERSION_NO. For any combination that found for A.BILL=B.BILL AND A.BILLER=B.BILLER may have different VERSION_NO. Now I want to fetch only the row which is having max(version_no) for the A.BILL=B.BILL AND A.BILLER=B.BILLER the combination. I needs the o/p shd be A3 3A 3 Likewise for all the rows. Pls help me. Thanks in Advance. Regards,

    M J 2 Replies Last reply
    0
    • A aaraaayen

      Hi Friends, I need help in the following query. SELECT A.BILL, A.BILLER, A.VERSION_NO, A.CODE, A.NAME,A.SEGMENT_CODE, A.COMMENT,B.BILL AS BILL, B.BILLER AS DW_BILLER, B.MCN AS DW_MCN, B.SO AS DW_SO, B.BG AS DW_BG, B.CODE AS DW_CODE, B.NAME AS DW_NAME,B.SEGMENT_CODE AS DW_SEGMENT_CODE FROM WEB_REF A, WEB_CUST B WHERE A.BILL=B.BILL AND A.BILLER=B.BILLER ORDER BY A.BILL The above query is working fine. and o/p like below: A3 3A 3 A3 3A 2 A3 3A 1 But now requirement is that, the table A consists VERSION_NO. For any combination that found for A.BILL=B.BILL AND A.BILLER=B.BILLER may have different VERSION_NO. Now I want to fetch only the row which is having max(version_no) for the A.BILL=B.BILL AND A.BILLER=B.BILLER the combination. I needs the o/p shd be A3 3A 3 Likewise for all the rows. Pls help me. Thanks in Advance. Regards,

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I don't know Oracle but in SQL Server I would use Top 1 and order by version_no desc. There will be something similar in Oracle.

      Never underestimate the power of human stupidity RAH

      N 1 Reply Last reply
      0
      • M Mycroft Holmes

        I don't know Oracle but in SQL Server I would use Top 1 and order by version_no desc. There will be something similar in Oracle.

        Never underestimate the power of human stupidity RAH

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Mycroft Holmes wrote:

        There will be something similar in Oracle.

        Yes. Oracle uses rownum. Something like, Select * from table where rownum = 1 order by version_no desc

        Navaneeth How to use google | Ask smart questions

        A 2 Replies Last reply
        0
        • N N a v a n e e t h

          Mycroft Holmes wrote:

          There will be something similar in Oracle.

          Yes. Oracle uses rownum. Something like, Select * from table where rownum = 1 order by version_no desc

          Navaneeth How to use google | Ask smart questions

          A Offline
          A Offline
          aaraaayen
          wrote on last edited by
          #4

          Hi Navaneeth, Thank you so much. I understood the rownum=1 will work when i do order by version_no desc. But in this case, order by is dynamic..that is user-given input. So whatever column user wish to come as order by he ll select that. Can u help me how in that case i have to use this query. Thanks lot really!!! Regards,

          1 Reply Last reply
          0
          • N N a v a n e e t h

            Mycroft Holmes wrote:

            There will be something similar in Oracle.

            Yes. Oracle uses rownum. Something like, Select * from table where rownum = 1 order by version_no desc

            Navaneeth How to use google | Ask smart questions

            A Offline
            A Offline
            aaraaayen
            wrote on last edited by
            #5

            Navaneeth, Thanks. If I user rownum=1 order by version_no desc, this will give the very first row, but i want the rows with version_no = max(version_no) in every code,unit_id combination. If I have 3 rows with this combination, among the 3 rows i wanted to display the row which is having max(version_no). Kindly help me. Thanks. Regards, Sageetha

            1 Reply Last reply
            0
            • A aaraaayen

              Hi Friends, I need help in the following query. SELECT A.BILL, A.BILLER, A.VERSION_NO, A.CODE, A.NAME,A.SEGMENT_CODE, A.COMMENT,B.BILL AS BILL, B.BILLER AS DW_BILLER, B.MCN AS DW_MCN, B.SO AS DW_SO, B.BG AS DW_BG, B.CODE AS DW_CODE, B.NAME AS DW_NAME,B.SEGMENT_CODE AS DW_SEGMENT_CODE FROM WEB_REF A, WEB_CUST B WHERE A.BILL=B.BILL AND A.BILLER=B.BILLER ORDER BY A.BILL The above query is working fine. and o/p like below: A3 3A 3 A3 3A 2 A3 3A 1 But now requirement is that, the table A consists VERSION_NO. For any combination that found for A.BILL=B.BILL AND A.BILLER=B.BILLER may have different VERSION_NO. Now I want to fetch only the row which is having max(version_no) for the A.BILL=B.BILL AND A.BILLER=B.BILLER the combination. I needs the o/p shd be A3 3A 3 Likewise for all the rows. Pls help me. Thanks in Advance. Regards,

              J Offline
              J Offline
              Johan Hakkesteegt
              wrote on last edited by
              #6

              And just using MAX doesn't work?

              SELECT A.BILL, A.BILLER, MAX(A.VERSION_NO) AS VERSION_NO,
              A.CODE, A.NAME,A.SEGMENT_CODE,
              A.COMMENT,B.BILL AS BILL, B.BILLER AS DW_BILLER,
              B.MCN AS DW_MCN, B.SO AS DW_SO, B.BG AS DW_BG,
              B.CODE AS DW_CODE, B.NAME AS DW_NAME,B.SEGMENT_CODE AS DW_SEGMENT_CODE
              FROM WEB_REF A, WEB_CUST B
              WHERE A.BILL=B.BILL AND A.BILLER=B.BILLER
              ORDER BY A.BILL

              My advice is free, and you may get what you paid for.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups