Click here to Skip to main content
14,426,761 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 1

Based on that Location = CityId link the two table the query would be:
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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100