0

I'm getting an error that says there isn't a unique table/alias for 'brand' but I set brand as b.name in my SELECT clause so I don't understand why I'm getting this issue.

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;

Alias error

  • There's too much wrong and/or suspicious with your query so that without knowing what your actually after I don't think you can get much help. You should [edit] your question and explain what you want your query to do. Don't forget to add the schema as `CREATE TABLE` statements, sample data as `INSERT INTO` statements and the desired result with that sample data. – sticky bit Apr 17 '19 at 23:15

1 Answers1

1

Recommend avoiding the FROM {comma list of tables}, and just use JOIN (which can use aliases as below.

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;
danblack
  • 12,130
  • 2
  • 22
  • 41