MySQL 查询错误代码:1066 不唯一 table/alias:'products_stock_location')?

MySQL query Error Code: 1066 Not unique table/alias: 'products_stock_location')?

我四处寻找答案,但似乎找不到。

我不是任何形式的 mysql 数据库分析师。查询根本不是我的强项。

我正在尝试从多个表中提取数据,我可以获得大部分数据,但最后一位数据我需要使用不同的 FROM。

这是我想合并在一起的两个工作查询 -

USE *database-name*;
SELECT products.products_id, products_with_attributes_stock.sku, products_description.products_name, products.products_model, products_with_attributes_stock.stock_attributes, products.products_price, products.products_cost, products_stock_location.quantity
FROM products, products_stock_location
INNER JOIN products_stock_location ON products.products_id=products_stock_location.products_id
INNER JOIN products_description ON products.products_id=products_description.products_id
INNER JOIN products_with_attributes_stock ON products.products_id=products_with_attributes_stock.products_id;


USE *database-name*;
SELECT stock_location.stock_location_name
FROM products_stock_location
INNER JOIN stock_location ON products_stock_location.stock_locations_id=stock_location.stock_location_id;

我已经试过了,但它给出了 1066 错误:

USE *database-name*;
SELECT products.products_id, products_with_attributes_stock.sku, products_description.products_name, products.products_model, products_with_attributes_stock.stock_attributes, products.products_price, products.products_cost, products_stock_location.quantity, stock_location.stock_location_name
FROM products, products_stock_location
INNER JOIN products_stock_location ON products.products_id=products_stock_location.products_id
INNER JOIN products_description ON products.products_id=products_description.products_id
INNER JOIN products_with_attributes_stock ON products.products_id=products_with_attributes_stock.products_id
RIGHT JOIN stock_location ON products_stock_location.stock_locations_id=stock_location.stock_location_id;

您在 'merged' 查询中使用了 table products_stock_location 两次。给其中之一一个别名,并在需要的地方使用别名。

编辑:我想第一个可以去掉。

变化:

FROM products, products_stock_location INNER JOIN products_stock_location ON products.products_id=products_stock_location.products_id

进入:

FROM products
INNER JOIN products_stock_location ON products.products_id=products_stock_location.products_id