我不理解SQL中的语法错误

时间:2013-07-18 09:26:30

标签: sql ingres

Insert into tbproppayh (id_payment)
SELECT s.id_payment FROM session.set_values s
WHERE EXISTS id_payment;

2013年7月18日星期四10:21:42 执行。 。

    E_US09C5 line 1, Syntax error on 'id_payment'.  The correct syntax is:
        SELECT [ALL|DISTINCT] target_list
          FROM table(s)
          [WHERE search_cond]
          [GROUP BY col(s)]
          [HAVING search_cond]
     [UNION subselect]
     [ORDER BY col(s)]
        (Thu Jul 18 10:21:42 2013)

继续

1 个答案:

答案 0 :(得分:4)

尝试:

INSERT INTO tbproppayh (id_payment)
SELECT s.id_payment
FROM   session.set_values s
WHERE  id_payment IS NOT NULL;  

WHERE EXISTS需要子查询:

WHERE EXISTS (SELECT ... FROM ...)

请参阅this example

发表评论后,只需使用DISTINCT即可避免插入重复值:

INSERT INTO tbproppayh (id_payment)
SELECT DISTINCT s.id_payment
FROM   session.set_values s
WHERE  id_payment IS NOT NULL;