Eu tenho um db com três tabelas
table1 table2 table3
Id Id Id
name price servicename
serviceTypeId Type
serviceId
nameId
Como construir uma consulta para me mostrar linhas únicascom apenas o nome da tabela1, o Tipo da tabela2 e o nome do serviço da tabela3? serviceTypeId é a chave estrangeira da tabela2 e serviceId é a chave estrangeira da tabela3, nameId é a chave estrangeira da tabela1. Estou tendo problemas com o conceito de junção interna da junção.
Respostas:
2 para resposta № 1De acordo com sua definição 1, a referência parece ter terminado, não sei se você está procurando
Select DISTINCT Table1.name,Table2.[Type],Table3.Servicename
From Table1
Join Table2 on Table1.serviceTypeId=Table2.ID
Join Table3 on Table3.ID=Table2.serviceId
ou
Select DISTINCT Table1.name,Table2.[Type],Table3.Servicename
From Table2
Join Table1 on Table1.Id=Table2.nameID
Join Table3 on Table3.ID=Table2.serviceId