question

David Chan avatar image
0 Likes"
David Chan asked David Chan commented

Nested SQL

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

  1. Table result = Table.query("UPDATE Test3 SET slprice1 = (SELECT slprice FROM Test2 WHERE Test3.ROW_NUMBER=Test2.ROW_NUMBER)"); //Nested SQL
  1. Table result = Table.query("SELECT slprice FROM Test2");
  2. for (int j=1; j<=result.numRows; j++)
  3. {
  4. Table result1 = Table.query("UPDATE Test3 SET slprice1= $1",result[j]["slprice"]);
  5. }
FlexSim 25.0.4
nested sql
1743670039633.png (2.7 KiB)
1743670079973.png (2.7 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered David Chan commented

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

  1. Table.query("UPDATE [Test3], [Test2] SET [Test3].[slprice1] = [Test2].[slprice] WHERE [Test3].[ROW_NUMBER] = [Test2].[ROW_NUMBER]")
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.