添加多个表以在PHP中插入查询

时间:2018-06-22 13:24:17

标签: php mysql insert

我正在用一个表将记录插入PHP Query,它工作正常。

    $Query="INSERT INTO siparisler (firma)
SELECT musteri_ismi from musteri_ekle where musteri_id='$Musteri_id'";

但是,当我尝试从第二个表中插入查询时,它不起作用:

    $Query="INSERT INTO siparisler (firma,urun)
SELECT musteri_ismi from musteri_ekle where musteri_id='$Musteri_id',
urun_id from urun_ekle where urun_id='$Urun_id'";

将来自不同表的两个数据插入到查询中的方式是什么?

1 个答案:

答案 0 :(得分:0)

INSERT
     INTO  siparisler (firma, urun) 
SELECT
        (
        SELECT  musteri_ismi
            from  musteri_ekle
            where  musteri_id='$Musteri_id' 
        ) AS firma, 
        (
        SELECT  urun_id
            from  urun_ekle
            where  urun_id='$Urun_id' 
        ) AS urun ;