这是我的查询:

INSERT INTO table (id, actions, date, comments, type, url, rating)
  SELECT * FROM (SELECT 'b7d54d99bf11', 'Information Exchanged', '1430463600', '', 'routine', 'http://example.com', '') AS tmp
    WHERE NOT EXISTS (SELECT url FROM table WHERE url = 'http://example.com')


我收到一条说Duplicate column name: ''的SQL错误,因为对于某些记录没有传递ratingcomments

如何避免该错误?有没有更好的方法来实现这一目标?

最佳答案

您必须为列添加别名

INSERT INTO table (id, actions, date, comments, type, url, rating)
  SELECT * FROM (SELECT 'b7d54d99bf11' as id,
                        'Information Exchanged' as actions,
                        '1430463600' as date,
                        '' as comments,
                        'routine' as type,
                        'http://example.com' as url,
                        '' as rating) AS tmp

10-06 05:40
查看更多