想知道如何通过选择插入来做到这一点

时间:2016-01-21 17:31:07

标签: sql mariadb

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的表中。我的问题是;原因不是外键,我不知道怎么用查询来说:

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. 

1 个答案:

答案 0 :(得分: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'