Select with 3 tables in SQL SERVER

0

Ineedtodoaselectonthemachinetable,butwhenIexecutemycommand

selectmaq.maqNip,equi.*fromtblMaquinamaqjointblEquipamentoequionequi.equId=maq.maqTipoEqui;

Thefollowingresultisdisplayed and I wanted the brand name, the template, and not just your ID to appear.

Can anyone help me to relate these three tables?

    
asked by anonymous 04.01.2019 / 15:13

4 answers

2

Just add another INNER JOIN to the other Marca table:

SELECT * 
  FROM tblMaquina maq
 INNER JOIN tblEquipamento equi 
    ON equi.equId = maq.maqTipoEqui;
 INNER JOIN tblMarca marca
    ON equi.marcaId = marca.marcaId;

Note: Do not forget to change the names of tables and fields to match your model. I made this as an example because I do not have the names of your fields.

    
04.01.2019 / 15:18
0

Try to do this:

select maq.maqNip, equi.*, marc.* from tblMaquina maq
inner join tblEquipamento equi on equi.equId = maq.maqTipoEqui
inner join tblMarca marc on marc.marcId = equi.equMarca
    
04.01.2019 / 15:23
0

Try running the following query

select 
   maq.Nip, 
   equip.tipo, 
   marc.nome 
from 
   Maquina maq,
   Marca marc,
   Equipamento equip,
where
   maq.tipo = equip.id
and
   equip.marca = marc.id;
    
04.01.2019 / 19:46
0

Also includes a (NOLOCK) not to allocate tables at processing time

SELECT * FROM tblMaquina (NOLOCK) maq  INNER JOIN tblEquipment (NOLOCK) equi ON equi.equId = maq.maqTipoEqui;  INNER JOIN tblMarch (NOLOCK) tag ON equi.marcaId = marca.marcaId;

    
07.01.2019 / 20:16