php - 我想插入来自其他表的 id 但我的查询有问题

标签 php mysql

我想插入来自其他表的 id 但我的查询有问题

INSERT INTO transport_assign_students 
(`transport_route_time_id`,`student_id`,`bus_stop`)
VALUES (SELECT(transport_route_time_id FROM transport_route_time WHERE bus_stop='indora'), 10017,'indora');

最佳答案

你应该这样使用插入选择

    INSERT INTO transport_assign_students (transport_route_time_id,student_id,bus_stop) 
    SELECT transport_route_time_id ,  10017,'indora'
    FROM transport_route_time 
    WHERE bus_stop='indora'

关于php - 我想插入来自其他表的 id 但我的查询有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53691397/

相关文章:

php - PHP 中的引用计数

php - 用 n 行更改一行的值(jquery、php、mysql)

php - 命名空间和自动加载错误,如何正确使用带自动加载的 PHP 命名空间?

mysql - 如何在 mysql 中显示具有计算的运行时值(即不在数据库中)的虚拟列?

mysql - 对短 mysql 表的多条件请求

php - Mysql:按日期交集选择,而不是之间

php - 使用 Slim Framework 重定向到另一个错误页面

php - 我如何从mysql中获取第n行的值?

mysql - 重新安装 WAMP,未找到 Wordpress 表但在 PHPMYADMIN 中

PHP将嵌套的json插入到mySQl中