MySQL 查询错误代码:1066 不是唯一的表/别名:“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;
I have looked around for an answer but I can't seem to find one.
I am not a mysql database anaylst in any shape or form. Queries are not my strongsuit at all.
I am trying to pull data from multiple tables, I can get most of the data how ever the last bit of data I need to use a different FROM.
Here are the two working queries I want to merge together -
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;
I have tried this but it gives the 1066 error:
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在“合并”查询中使用了
products_stock_location
表两次。为其中之一指定一个别名,并在需要时使用该别名。编辑:我想第一个可以删除。
变成
:
You use the table
products_stock_location
twice in your 'merged' query. Give one of them an alias and use the alias where needed.Edit: I guess the first one can be removed.
Change:
Into: