Is there a way to add rows of Table A to table B using SQL? Both have the same structure, (columns). I wouldnt want to use SELECT and add each column manually because my tables have many columns.
Below an image of my question.
Is there a way to add rows of Table A to table B using SQL? Both have the same structure, (columns). I wouldnt want to use SELECT and add each column manually because my tables have many columns.
Below an image of my question.
Hi Enrique Elizaga,
Here's a solution using loops and SQL queries. Maybe a better solution is available and on searching through the user manual, couldn't find UNION type function to unite two tables. Not sure about, whether this can be done using INNER JOIN. This solution is something, which quickly came to my mind.
On a higher level, what I have did here is stored the data from two tables into an array and updated the second table with the data stored in the array.
Table TableA = Table("TableA"); Table TableB = Table("TableB"); int ArraySize = TableA.numRows + TableB.numRows; Array TableDataRows = Array(ArraySize); Array TableDataCols = Array(TableA.numCols); Table resultA = Table.query("SELECT *FROM TableA");// Selecting From TableA int NrofTableARows = TableA.numRows; int NrofTableACols = TableA.numCols; for(int i=1;i<=NrofTableARows;i++) // Storing Result in the Array { for(int k=1;k<=NrofTableACols;k++) { TableDataCols[k]= resultA[i][k]; } TableDataRows[i] = TableDataCols.clone(); } Table resultB = Table.query("SELECT *FROM TableB");// Selecting From TableB int NrofTableBRows = TableB.numRows; int NrofTableBCols = TableB.numCols; for(int i=1;i<=NrofTableBRows;i++)// Storing Result in the Array { for(int k=1;k<=NrofTableBCols;k++) { TableDataCols[k]= resultB[i][k]; } TableDataRows[i+ NrofTableBRows] = TableDataCols.clone(); } TableB.setSize(ArraySize,3);//Setting the table size. for(int i=1;i<=ArraySize;i++) // Writing Data to the Table from Array { for(int k=1;k<=NrofTableBCols;k++) { TableB[i][k]= TableDataRows[i][k]; } }
See the attached model.
Regards,
Arun KR
Wow @Arun KR that seems complicated. Wouldnt it be easier:
for(int ROW=1; ROW <= Table("Origin").numRows; ROW++) { Table("Destination").addRow(); for(int COL=1; COL<= Table(x).numCols; COL++) { Table("Destination")[Table("Destination").numCols][COL] = Table("Origin")[ROW][COL]; } }
8 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved