我有两张桌子。
i) order_details:
CREATE TABLE `order_details` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `content` text, `id_employee` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FK_id_employee` (`id_employee`), CONSTRAINT `FK_id_employee` FOREIGN KEY (`id_employee`) REFERENCES `employees` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
ii) 雇员:
CREATE TABLE `employees` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `firstname` text NOT NULL, `lastname` text NOT NULL, `salary` FLOAT DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 ;
我想获取员工 3 负责的订单的名字、姓氏和详细信息。我用这个:
SELECT lastname, firstname, content FROM order_details INNER JOIN employees USING (id_employee) WHERE id_employee = 3;
但我收到此错误消息:ERROR 1054 (42S22): Unknown column 'id_employee' in 'from clause'
并且不知道它来自哪里:(