2016-01-21 92 views
1
INSERT INTO report (server_id, reported_id, reporting_id, admin_id) 
      SELECT s.server_id, rep.reported_id, ru.reporting_id, a.admin_id 
      FROM server s, reported_user rep, reporting_user ru, admin a 
      WHERE s.server_port = 'port' 
      AND rep.reported_steam_id = 'id' 
      AND ru.reporting_steam_id = 'id' 
      AND a.admin_id = '0' 

正如您在上面看到的,我有一個查詢從其他表中提取信息並將其插入到名爲report的表中。我的問題是,原因是不是外鍵,我不知道如何使查詢與讓說:想知道如何使用select插入

INSERT INTO report (server_id, reported_id, reporting_id, admin_id, reason) 
      SELECT s.server_id, rep.reported_id, ru.reporting_id, a.admin_id 
      FROM server s, reported_user rep, reporting_user ru, admin a 
      WHERE s.server_port = 'port' 
      AND rep.reported_steam_id = 'id' 
      AND ru.reporting_steam_id = 'id' 
      AND a.admin_id = '0', 
      "TEST"; // <-- Does not work. Trying to insert a text string here. 
+0

爲'reason'你想添加的「測試」串吧? ? –

+0

這是正確的。所有(server_id,reported_id,reporting_id和admin_id)是對其他表的引用,但「reason」不是。那是一個塔內的「報告」 – Perelan

回答

1

試試這個

 INSERT INTO report (server_id, reported_id, reporting_id, admin_id, reason) 
     SELECT s.server_id, rep.reported_id, ru.reporting_id, a.admin_id,"TEST" 
     FROM server s, reported_user rep, reporting_user ru, admin a 
     WHERE s.server_port = 'port' 
     AND rep.reported_steam_id = 'id' 
     AND ru.reporting_steam_id = 'id' 
     AND a.admin_id = '0' 
+0

Thansk,只是想通了!這是對的 :) – Perelan