我收到一个错误消息,说“ brand”没有唯一的表/别名,但是我在SELECT子句中将brand设置为b.name,所以我不明白为什么会遇到这个问题。
SELECT p.productname as product, b.name as brand
from product p, brand b, foodtype f
inner join brand
on p.brand_id = b.id
inner join foodtype
on p.foodtype_id = f.id
inner join brand
on p.petcat_id = 2
inner join brand
on p.productcat_id = pr.id
order by p.brand_id, p.product_name;
别名错误
答案 0 :(得分:1)
建议避免使用FROM {comma list of tables}
,而只需使用JOIN
(可以使用以下别名)。
SELECT p.productname as product, b.name as brand
from product p
inner join brand b
on p.brand_id = b.id
inner join foodtype f
on p.foodtype_id = f.id
where
p.petcat_id = 2
order by p.brand_id, p.product_name;