title: How to join in sql with multiple tables (need) join multiple references?
body: <p>Some table only have identity columns but this is because this is a example only.</p>
  
  <pre><code>create table producto(
  idproducto int identity primary key
  )
  
  create table inventario(
  idInventario id int identity primary key,
  idproducto int,
  foreign key (idproducto) references producto(idproducto)
  )
  
  create table sucursal(
  idSucursal id int identity primary key
  )
  
  create table inventariosucursal(
  idinventariosucursal id int primary key,
  idsucursal int,
  idinventario int,
  foreign key (idsucursal) references sucursal (idsucursal),
  foreign key (idinventario) references inventario (idinventario),
  )
  
  create table mejoresventasxsucursal
  (
  mejoresventasxsucursal id int primary key,
  idsucursal int,
  idproducto int,
  foreign key (idsucursal) references sucursal(idsucursal),
  foreign key (idproducto) references producto (idproducto)
  )
  </code></pre>
  
  <p>What do I need?</p>
  
  <p>select the stocking ( inventario table ) by every branch office (sucursal table) but only most selled products (mejoresventasxsucursal table).</p>
  
  <p>the problem is mejoresventasxsucursal  table does "join" with 2 tables product and sucursal but after i have other table with does "join" with same 2 tables product and sucursal.</p>
  
  <pre><code>select s.id,i.id,p.id,
  from producto p
  join inventario i on p.idproducto = i.idproducto
  join inventariosucursal i_s on i_s.idinventario = i.idinventario
  join sucursal s on i_s on i_s.idsucursal = s.idsucursal
  join producto p on i.producto = p.idproducto
  join mejoresventasxsucursal mv on mv.idsucursal = s.idsucursal
  </code></pre>
  
  <p>Here is the problem. I need join mejoresventasxsucursal with producto. I know I could do something as join producto p2 but I would like to know what is the best way for join with producto. I know other solution is in where condition doing where p.idproducto=mv.idprocucto</p>