---
title: "SQL  连接查询"
author: "编程足球"
date: "2011-07-07T21:49:32Z"
tags: []
categories: ["Web前端"]
slug: "sql"
draft: false
lastmod: "2011-07-07T21:52:53Z"
id: 1119150
url: "https://lingf.iteye.com/blog/1119150"
---

连接查询是指一个查询同时涉及到两个及以上的表。包括：
等值连接,自然连接,非等值连接,自身连接,外连接,复合查询.等...
<span style="color:red">1. 等值连接 于非等值连接</span>

```java

//   查询每个学生及选课的情况
select Student.*,SC.*
from Student,Sc
where Student.Sno = SC.Sno;

```


<span style="color:red">2.自然连接</span>
在等值连接中把目标列的重复属性去掉则为： 自然连接

```java

//   查询每个学生及选课的情况
Select Student.Sno,Student.name,Ssex,Sage,Sdept,Cno,Grade
from Student,Sc
where Student.Sno = SC.Sno;

```


<span style="color:red">3.自身连接</span>

```java

//  查询每门课的间接选修课(即选修课的选修课)
select First.Cno,Second.Cpno
From Course First,Course Second
Where First.Cpno = Second.Cno;


```


<span style="color:red">4.外连接</span>
<span style="color:red">    </span>