我正在学习数据库查询,我遇到了一种情况,我根据某些条件得到了字段
select brandname
from shopping_men_women_fashion.shoppingbrandmaster
where shoppingbrandmaster.brandid =clothing.brandid
抛出错误
missing FROM-clause entry for table clothing.brandid
这个错误是什么?
答案 0 :(得分:1)
您错过了加入clothing Table
SELECT shoppingbrandmaster.brandname
FROM shopping_men_women_fashion.shoppingbrandmaster,
clothing
WHERE shoppingbrandmaster.brandid = clothing.brandid
OR
SELECT shoppingbrandmaster.brandname
FROM shopping_men_women_fashion.shoppingbrandmaster
JOIN clothing
ON shoppingbrandmaster.brandid = clothing.brandid
答案 1 :(得分:1)
您可以使用表别名和USING
简化语法:
SELECT s.brandname
FROM shopping_men_women_fashion.shoppingbrandmaster s
JOIN shopping_men_women_fashion.clothing c USING (brandid);
我假设你的第二个表也存在于模式shopping_men_women_fashion
中。如果对一个表进行模式限定是有意义的,那么对另一个表进行模式限定是有意义的。
(此示例中未引用c
的列别名clothing
,可以将其删除。)