4 Replies Latest reply on Jul 13, 2015 1:04 PM by prashanthi1

    insert "update procedures" query by inner join.

    prashanthi1

      Hello,

       

      I am trying to select and insert in to multiple tables which has one common column.

      I have been able to select from tables by inner joins. how do I right the same query in update procedures by inner joins??

       

      sample select query - >

       

      SELECT

        a.ID, name, b.address, b.phoneno, c.address AS address_1, c.phoneno AS phoneno_1

        FROM

        (OracleConn.table1 AS a INNER JOIN OracleConn.table2 AS b ON a.ID = b.ID) INNER JOIN OracleConn.table3 AS c ON a.ID = c.ID

       

      Any help much appreciated.

      Thanks in advance,

      Prashanthi.

        • 1. Re: insert "update procedures" query by inner join.
          rareddy

          see an example of the insert here. Parsing errors in Designer "Error in parsing of sql - Encountered " "new" "new "" at line 4, column 75"

           

          In Designer, where you entered the "select" transformation with inner joins, there tabs for insert and update and delete. 

           

          Also see similar request here composite insert using Teiid

          • 2. Re: insert "update procedures" query by inner join.
            prashanthi1

            Hi Ramesh,

             

            Thanks for the reply.

            I have been able to insert in to multiple tables by using update procedures, but i am facing problem in inserting when the tables have to joined by INNER JOIN.

            for the select query i have given above i am not able to right a equivalent insert query.

             

            If is one common column(say ID) in all the three tables, can i insert it by INNER JOIN like i did for select(i.e enter value of ID once and it inserts in to all the three tables) or do i need to explicitly insert in to each table after joining them?

             

            Thanks,

            Prashanthi.

            • 3. Re: insert "update procedures" query by inner join.
              rareddy

              There are NO JOINS in a INSERT query. INSERT by definition only works against single table.

               

              If there are two source tables like table A { X, Y} and table B {X, Z} and, and your Teiid view table is exposing view like  C {X, Y, Z} where the the transformation is like

               

              SELECT A.X, A.Y, B.Z FROM A INNER JOIN B ON A.X = B.X
              

               

              then the INSERT procedure will be like below. Note that the Insert you are writing is against the source tables you built the View with, not to the View itself.

               

              FOR EACH ROW 
              BEGIN ATOMIC 
                INSERT INTO A (X, Y) values ("NEW".X, "NEW".Y); 
                INSERT INTO B (X, Y) values ("NEW".X, "NEW".Y); 
              END
              

               

              UPDATE will be like

               

              FOR EACH ROW 
              BEGIN ATOMIC 
                IF (CHANGING.Y)
                BEGIN
                  UPDATE TABLE A  SET Y= "NEW".y; 
                  UPDATE TABLE B  SET Y= "NEW".y;  
                END
              END
              

               

              DELETE query will look like

               

              FOR EACH ROW 
              BEGIN ATOMIC 
                  DELETE FROM A  WHERE X = OLD.X; 
                  DELETE FROM B  WHERE X = OLD.X;  
              END
              

               

              Then once the VDB is built, you can issue the queries like below against the View Table C

               

              SELECT * FROM C;
              INSERT INTO C (X, Y, Z) VALUES (1, 2, 3)
              UPDATE C SET Y=4, Z= 5 WHERE X = 1
              DELETE FROM C WHERE X = 1
              

               

               

              Hopefully this explains clearly what needs to be done.

               

              Ramesh..

              • 4. Re: insert "update procedures" query by inner join.
                prashanthi1

                This is very clear now. Thank you very much Ramesh.