连接两个表并在一个表中显示

编程入门 行业动态 更新时间:2024-10-11 21:32:21
本文介绍了连接两个表并在一个表中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的朋友,大家好!! 正在使用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.

更多推荐

连接两个表并在一个表中显示

本文发布于:2023-10-08 01:09:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471065.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!