Darkmage
Darkmage

Reputation: 1603

How do I construct a query with join or inner join

I have a db with three tables

table1         table2       table3
Id             Id           Id
name           price        servicename
serviceTypeId  Type
               serviceId
               nameId

How do I construct a query to show me unique rows with only the name of table1 the Type of table2 and the servicename of table3? serviceTypeId is foreign key for table2, and serviceId is foreign key for table3, nameId is foreign key of table1.. I'm struggling with the join inner join concept.

Upvotes: 0

Views: 130

Answers (1)

bummi
bummi

Reputation: 27367

Form your definition 1 reference seems to be over, I'm not shure if you are looking for

Select DISTINCT Table1.name,Table2.[Type],Table3.Servicename
From Table1
Join Table2 on Table1.serviceTypeId=Table2.ID
Join Table3 on Table3.ID=Table2.serviceId  

or

Select DISTINCT Table1.name,Table2.[Type],Table3.Servicename
From Table2
Join Table1 on Table1.Id=Table2.nameID
Join Table3 on Table3.ID=Table2.serviceId 

Upvotes: 2

Related Questions