Click here to Skip to main content
15,885,636 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends, Good Day!!

am working on Sql Server 2005 Database.... I want to Join Two Tables.

In First Table -- Name of Table -> TRAINS
In this it has Fields as TrainNo, TrainName,Location

In second Table -- Name of Table -> CITIES

In this Cities table it has Fields as CityId, CityName

Now I want to display the data of cityname in Trains Table.

I need Final table as TrainNo, TrainName,Location, CityName

Please help me how to join these tables to one table.

THANKS IN ADVANCE.
Posted
Comments
Mario Majčica 26-Nov-12 3:09am    
What is the reference that joins two tables? Location == CityId?
Prasad Guduri 27-Nov-12 1:23am    
What is the common column in those two tables????

1 solution

Based on that Location = CityId link the two table the query would be:
SQL
SELECT T.TrainNo, T.TrainName, T.Location, C.CityName
FROM TRAINS AS T
JOIN CITIES AS C ON C.CityID = T.Location

Read SQL Joins[^] for the different type of joins avaiable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900