Home  >  Article  >  Database  >  T-Sql(四)表关联和视图(view)

T-Sql(四)表关联和视图(view)

WBOY
WBOYOriginal
2016-06-07 17:38:42901browse

今天讲下T-sql中用于查询的表关联和视图,我们平时做项目的时候会遇到一些复杂的查询操作,比如有班级表,学生表,现在要查询一个学生列表,要求把学生所属班级名称也查询出来,这时候简单的select查询就不行了,需要关联班级表,因为学生是一定属于某一个班

  今天讲下T-sql中用于查询的表关联和视图,我们平时做项目的时候会遇到一些复杂的查询操作,比如有班级表,学生表,现在要查询一个学生列表,要求把学生所属班级名称也查询出来,这时候简单的select查询就不行了,需要关联班级表,因为学生是一定属于某一个班级的,所以关联的示例需要自关联。

  表关联(join)  

  下面列一些示例代码,,帮助大家理解。

Tree t1 inner join Tree t2 on t1.NO=t2.ParentNo ; tree ParentNo ); tree );

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn