Eztyfoe Eztyfoe -4 years ago 110
SQL Question

How to join 3 tables in SQL Server?

I have 3 tables :


  1. Transaction (ID_Transcation)

  2. Transaction Detail (ID_Transaction_Detail, ID_Transaction, ID_Services)

  3. Services (ID_Services, Name)



I want to get only the name of the services, based on the
ID_Transaction
in the
Transaction
table.

The table and output that I want:

enter image description here

Code I tried:

Select se.Name
from Transactions as td, Services as se
where td.ID_Transaction = 'TRA1'


But the output is displaying all the name from service table

Answer Source
select c.name 
from Transaction as a
inner join Detail as b
on a.ID_Transaction = b.ID_Transaction
inner join Services as c
on b.id_services = c.id_services;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download