我正在使用MySQL。我有以下查询:
SELECT DISTINCT c.car_id FROM cars AS c JOIN customer_cars bb ON bb.age=40;
当我运行上述查询时出现错误:
ERROR 1054 (42S22): Unknown column 'c.car_id' in 'field list'
我哪里错了?
(cars
和customer_cars
表都有car_id
列)
答案 0 :(得分:2)
你不能这样做:
SELECT DISTINCT car_id FROM customer_cars WHERE age = 40;
答案 1 :(得分:1)
这对我没有任何错误
CREATE TEMPORARY TABLE cars (car_id INT NOT NULL);
CREATE TEMPORARY TABLE customer_cars (car_id INT NOT NULL, age INT NOT NULL);
SELECT DISTINCT c.car_id FROM cars AS c JOIN customer_cars bb ON bb.age=40;
这与连接条件也有效:
SELECT DISTINCT c.car_id
FROM
cars AS c
JOIN
customer_cars bb USING (car_id)
WHERE
bb.age=40;
该错误不适用于该查询...