• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Urgent Oracle SQL Question (INNER JOIN)

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Urgent Oracle SQL Question (INNER JOIN)

    Hi folks,

    I have two tables, one containing detail records and one containing header records. The common columns are let's say CODE and CLIENT.

    What I want to do is to select info from the detail records but join to the header record, like this:

    SELECT
    A.CODE, A.CLIENT, A.NAME,
    B.DATE, B.AMOUNT
    FROM HEADER A
    INNER JOIN DETAIL B something

    The pseudo-code for "something" is

    FOR RECORDS WHERE A.CLIENT = B.CLIENT AND A.CODE = B.CODE

    I think I can do it like this:

    INNER JOIN ON A.CLIENT = B.CLIENT AND A.CODE = B.CODE

    or

    INNER JOIN ON A.CLIENT||A.CODE = B.CLIENT||B.CODE

    Or would this do the same / be better ?

    USING (CLIENT, CODE)

    I don't have access to the target system, so I'm giving the local oppo instructions by email. It would be excellent if what I told him worked!

    Thanks in advance!!

    #2
    Select
    A.code, A.client, A.name,
    B.date, B.amount
    From Header A
    Inner Join Detail B
    on
    A.client = B.client
    And A.code = B.code
    Coffee's for closers

    Comment


      #3
      Originally posted by Spacecadet View Post
      Select
      A.code, A.client, A.name,
      B.date, B.amount
      From Header A
      Inner Join Detail B
      on
      A.client = B.client
      And A.code = B.code
      Many thanks!

      What's the approved CUK way of sending free beers in gratitude?

      Comment


        #4
        Originally posted by Platypus View Post
        Many thanks!

        What's the approved CUK way of sending free beers in gratitude?
        http://www.beer4home.co.uk/
        Coffee's for closers

        Comment


          #5
          Why not

          Code:
          SELECT a.code
          ,      a.client
          ,      a.name
          ,      b.date
          ,      b.amount
          from   header a
          ,      detail b
          where  a.client = b.client
          and    a.code   = b.code
          ?

          Oh - and "date" is a really bad name for a column, since it's a reserved word.
          Best Forum Advisor 2014
          Work in the public sector? You can read my FAQ here
          Click here to get 15% off your first year's IPSE membership

          Comment


            #6
            Originally posted by TheFaQQer View Post
            Why not

            Code:
            SELECT a.code
            ,      a.client
            ,      a.name
            ,      b.date
            ,      b.amount
            from   header a
            ,      detail b
            where  a.client = b.client
            and    a.code   = b.code
            ?

            Oh - and "date" is a really bad name for a column, since it's a reserved word.
            that would work fine too, technically no reason not to
            Personally I'd say that good practice dictates otherwise though
            Coffee's for closers

            Comment


              #7
              Originally posted by Spacecadet View Post
              that would work fine too, technically no reason not to
              Personally I'd say that good practice dictates otherwise though
              Yeah it's not proppa ansi SQL innit.
              It's about time I changed this sig...

              Comment


                #8
                Originally posted by Platypus View Post
                I don't have access to the target system, so I'm giving the local oppo instructions by email. It would be excellent if what I told him worked!

                Sure, we believe you. Cheating on a technical test, naughty.
                Feist - 1234. One camera, one take, no editing. Superb. How they did it
                Feist - I Feel It All
                Feist - The Bad In Each Other (Later With Jools Holland)

                Comment


                  #9
                  Originally posted by PAH View Post
                  Sure, we believe you. Cheating on a technical test, naughty.
                  Actually, working on Plan B

                  Comment


                    #10
                    Originally posted by TheFaQQer View Post
                    Oh - and "date" is a really bad name for a column, since it's a reserved word.
                    I simplified the statement so az yu lot cud undast& it like!

                    Comment

                    Working...
                    X