我有一个SQL查询,看起来像这样:
insert into tableA(order_id, contractnotenumber, shipmentdate, comment)
values ((select entity_id from tableb where increment_id = '12345678'),
'', '1970-01-01', '');
现在,如果子查询((从tableb中选择entity_id,其中increment_id ='12345678'))返回null,则插入不起作用。我想要的是一个简单的方法,如果子查询返回null,不要做任何事情。我尝试插入忽略,但这会插入行而不是null,这有效,但它不是我想要的。在SQL Server中我使用如果不存在(选择...),但这不适用于MYSQL。
想法?
谢谢!
答案 0 :(得分:1)
insert into tableA(order_id, contractnotenumber, shipmentdate, comment)
select entity_id, '', '1970-01-01', '' from tableb where increment_id = '12345678'
如果在tableb
答案 1 :(得分:0)
你也可以试试mysql>插入忽略