错误:“字段列表”中的未知列'makeId'

时间:2014-11-06 00:44:33

标签: mysql sql

当我使用INSERT从表中获取信息并将其放入vehicleNormal时,我一直在'字段列表'中获得一个未知列'makeId'。

INSERT INTO vehicleNormal (makeId, modelId, year, cylinders, driveId, mpgHighway, mpgCity, fueltypeId)
(SELECT makeId, modelId, year, cylinders, driveId, mpgH, mpgC, fueltypeId
FROM vehicle
JOIN vehicleMake ON vehicle.make = vehicleMake.make
JOIN vehicleModel ON vehicle.model = vehicleModel.model
JOIN vehicleDrive ON vehicle.drive = vehicleDrive.drive
JOIN vehicleFuelType ON vehicle.fueltype = vehicleFuelType.fueltype);

当我的桌子有'makeId'时......

CREATE TABLE ‘vehicleNormal’ (
‘vehicleId’ INT NOT NULL AUTO_INCREMENT,
‘fuelType’ VARCHAR (255) DEFAULT NULL,
‘makeId’ INT (11) DEFAULT NULL,
‘modelId’ INT (11) DEFAULT NULL,
‘year’ INT (11) DEFAULT NULL,
‘cylinders’ INT (11) DEFAULT NULL,
‘driveId’ INT (11) DEFAULT NULL,
‘mpgHighway’ DECIMAL(10,2),
PRIMARY KEY (‘vehicleId’)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

任何帮助都会很棒。 :/

2 个答案:

答案 0 :(得分:1)

刚添加了车辆。到SELECT中的所有列。谢谢Gordon Linoff指出我正确的方向。

INSERT INTO vehicleNormal (makeId, modelId, year, cylinders, driveId, mpgHighway, mpgCity, fueltypeId)
(SELECT vehicle.make, vehicle.model, vehicle.year, vehicle.cylinders, vehicle.drive, vehicle.mpgHighway, vehicle.mpgCity, vehicle.fueltype
FROM vehicle
JOIN vehicleMake ON vehicle.make = vehicleMake.make
JOIN vehicleModel ON vehicle.model = vehicleModel.model
JOIN vehicleDrive ON vehicle.drive = vehicleDrive.drive
JOIN vehicleFuelType ON vehicle.fueltype = vehicleFuelType.fueltype);

答案 1 :(得分:0)

您在INSERT中提供了目标表的表定义,但没有为源表提供。如果源表中不存在名为makeId的字段,则SELECT将生成错误。