0

What I am trying to do is add a section the website that automatically assigns a department to a product when an administrator creates a product. For example, if I create a "t-shirt" product then it gets assigned the the "shirts" department. I need to get the tables connected in the db so that when a department is loaded, all the associated products show up. When I run a join between the two tables this is what I am running:

select d.Name, p.Name
       from products p
        inner join departments d on p.Id = d.Id

And I'm getting my only two products which I've manually assigned a department.

Can I get some help with what I need to do next to get every product automatically associated with a department?

maxshuty
  • 9,708
  • 13
  • 64
  • 77

1 Answers1

1
select d.Name, p.Name
       from products p
        inner join departments d on p.Id = d.Id

you use wrong key to link, (on p.Id = d.Id) try on p.Id= d.foreign_key

maxshuty
  • 9,708
  • 13
  • 64
  • 77
Shana
  • 70
  • 1
  • 1
  • 8