插入现有值并从另一个表中对其进行排序

Insert the existing value and sort it from another table

I'm trying to call data from table A and but table A is sorted from table B.

Detail: Table A stores "ID" and table B stores numbers, I want to sort table A based on the numbers in table B.

I tried the code below but it didn't work

$result = $db->Query("INSERT INTO `session`(`id`)VALUES('".$id['tableA']."' ON SELECT * FROM `tableB` WHERE `number`<'500' )") ;

After I run the code does not save to the database.

I hope the experts can solve my problem. thank you

remove the ON in your syntax as the right query is:

INSERT INTO [table] SELECT * FROM [anothertable]

as explained in detail in MySQL documentation

As for your situation, the right query should be:

INSERT INTO `session`(`id`) SELECT `id` FROM `tableB` WHERE `number` < 500;