Nested SQL

Nested SQL

chanykE2WUT
Explorer Explorer
19 Views
2 Replies
Message 1 of 3

Nested SQL

chanykE2WUT
Explorer
Explorer

[ FlexSim 25.0.4 ]

Hi I am trying add the value from Table 1 column slprice to another table Table 2 column slprice1 using one line of SQL. I have tried using nested SQL, but all fails. The only code that works is with a for loop which I tried to avoid. Any suggestion?

1743670039633.pngTable 1

1743670079973.pngTable 2

Table result = Table.query("UPDATE Test3 SET slprice1 = (SELECT slprice FROM Test2 WHERE Test3.ROW_NUMBER=Test2.ROW_NUMBER)"); //Nested SQL
Table result = Table.query("SELECT slprice FROM Test2");
for (int j=1; j<=result.numRows; j++)
{
Table result1 = Table.query("UPDATE Test3 SET slprice1= $1",result["slprice"]);
}
0 Likes
Accepted solutions (1)
20 Views
2 Replies
Replies (2)
Message 2 of 3

moehlmann_fe
Explorer
Explorer
Accepted solution

The MySQL syntax from the link below works. (Square brackets not strictly necessary)

https://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match

Table.query("UPDATE [Test3], [Test2] SET [Test3].[slprice1] = [Test2].[slprice] WHERE [Test3].[ROW_NUMBER] = [Test2].[ROW_NUMBER]")
0 Likes
Message 3 of 3

chanykE2WUT
Explorer
Explorer
@Felix Möhlmann Thanks

David

0 Likes