亲爱的朋友,大家好!! 正在使用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.
推荐答案基于Location = CityId链接两个表,查询将是: 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
阅读 SQL联接 [ ^ ].
Read SQL Joins[^] for the different type of joins avaiable.
更多推荐
连接两个表并在一个表中显示
发布评论