2 Replies Latest reply: Nov 10, 2016 12:43 AM by Anand Chouhan RSS

    How to use composite keys

    laxman V

      Hi i have requirement that i need to use the composite keys to avoid the synthetic keys,

      can anyone let me know how to create and use them,

       

      my requirement is that i have 2 tables like below

       

      Month                      ID                   details

      Jan                         101                         x

      Feb                         102                         y

      March                      103                         z

       

       

       

      Month                          ID                OP        

      Jan                              101               a

      Feb                              102               b

      March                           103               c

       

      Now i want these 2 tables to like below

       

       

      Month                      ID                   details          OP

      Jan                         101                         x               a

      Feb                         102                         y               b

      March                      103                         z               c

       

      how can i get it with composite key.

       

      if i use joins it looking like below

       

      Month                      ID                   details          OP

      Jan                         101                         x               -

      Feb                         102                         y               -

      March                      103                         z               -

       

       

       

      Month                          ID                  details                  OP        

      Jan                              101                   -                          a

      Feb                              102                    -                         b

      March                           103                    -                         c

       

       

      please let me know the way

       

      thanks in advance

        • Re: How to use composite keys
          Tresesco B

          Try like:

           

          Load

                   Month,

                   ID,

                   details,

                   Month&ID as CompKey

          From Table1;

          Join

          Load

                  Month&ID as CompKey,

                  OP

          From Table2;

           

          Drop field CompKey;

          • Re: How to use composite keys
            Anand Chouhan

            You can do this way also

             

            Simple Join

             

             

            Tab1:
            LOAD * INLINE [
            Month, ID, details
            Jan, 101, x
            Feb, 102, y
            March, 103, z
            ]
            ;

            Join(Tab1)
            LOAD * INLINE [
            Month, ID, OP
            Jan, 101, a
            Feb, 102, b
            March, 103, c
            ]
            ;

             

             

            By Composite Keys

             

            Tab1:
            LOAD Month&ID as %Key,Month as Months, ID as User_ID, details;
            LOAD * INLINE [
            Month, ID, details
            Jan, 101, x
            Feb, 102, y
            March, 103, z
            ]
            ;

            Join(Tab1)

            LOAD Month&ID as %Key, OP;
            LOAD * INLINE [
            Month, ID, OP
            Jan, 101, a
            Feb, 102, b
            March, 103, c
            ]
            ;



            Regards

            Anand