问题描述
亲爱的朋友,大家好!!
正在使用Sql Server 2005数据库....我想加入两个表.
在第一个表格中-表格名称-> TRAINS
在该字段中,其字段为TrainNo,TrainName,Location
在第二个表格中-表格名称->城市
在此城市表中,其字段为CityId,CityName
现在,我想在火车表"中显示城市名称的数据.
我需要Final Table作为TrainNo,TrainName,Location,CityName
请帮助我如何将这些表连接到一个表.
谢谢.
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.
推荐答案
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.
这篇关于连接两个表并在一个表中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!