简体   繁体   English

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

[英]Insert the existing value and sort it from another table

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. 我正在尝试从表A调用数据,但是表A是从表B排序的。

Detail: Table A stores "ID" and table B stores numbers, I want to sort table A based on the numbers in table B. 详细信息:表A存储“ ID”,表B存储数字,我想根据表B中的数字对表A进行排序。

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: 删除语法中的ON ,因为正确的查询是:

INSERT INTO [table] SELECT * FROM [anothertable]

as explained in detail in MySQL documentation MySQL文档中详细说明的

As for your situation, the right query should be: 根据您的情况,正确的查询应为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM