我想将数据添加到查找表中。
locations_borrowers (id_location_borrower (PK),id_borrower (FK),id_location (FK))
来自3个不同的表格:
borrowers (id_borrower (PK),forename,姓氏)locations (id_location (PK),街道,城镇)all_proto (borrower_forename,borrower_surname,街道,城镇,职业,电话)我写了以下文章:
INSERT INTO schema.locations_borrowers (id_borrower, id_location)
SELECT borrowers.id_borrower, locations.id_location FROM borrowers JOIN schema.all_proto
ON borrowers.forename = all_proto.borrower_forename AND borrowers.surname = all_proto.borrower_surname
LEFT JOIN locations ON locations.street = all_proto.street AND locations.town = all_proto.town;我犯了一个1048错误,怎么了?
发布于 2015-12-22 18:36:59
MySQL ::Error: 1048列对于Insert不能为空
由于您使用的是LEFT JOIN,列locations.id_location可能为null。
这应该始终是INNER JOIN,因为您期望这两个值都是NOT NULL。(如果不是,这张桌子没有任何意义,不是吗?)
https://stackoverflow.com/questions/34422253
复制相似问题