连接两个表并在一个表中显示 [英] Join two tables and display in one table

查看:73
本文介绍了连接两个表并在一个表中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,大家好!!

正在使用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.


这篇关于连接两个表并在一个表中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆