【发布时间】:2012-05-07 09:03:31
【问题描述】:
我有一个 SQL 查询,它看起来像这样:
insert into tableA(order_id, contractnotenumber, shipmentdate, comment)
values ((select entity_id from tableb where increment_id = '12345678'),
'', '1970-01-01', '');
现在,如果子查询 ((select entity_id from tableb where increment_id = '12345678')) 返回 null,则插入不起作用。我想要的是一种简单的方法,即如果子查询返回 null,则不做任何事情。我尝试插入忽略,但这会插入 0 而不是 null 的行,这有效,但它不是我想要的。在 SQL Server 中,我使用了 if not exists(select...),但这不适用于 MYSQL。
想法?
谢谢!
【问题讨论】: