MySQL连接查询

  | 转载时请务必以超链接形式标明文章原文链接和作者信息及本版权声明。
原文链接:http://www.liaojl.com/archives/2008/08/mysql-join.html

左连接(Left Join)查询

创建学生(student)表

CREATE TABLE student (
id int,
name varchar(20));

创建成绩(SC)表

CREATE TABLE SC (
id int,
grand char(10));

插入测试数据

INSERT INTO student VALUES (1, "Daniel");
INSERT INTO student VALUES (2, "Sean");
INSERT INTO student VALUES (3, "Leo");
INSERT INTO student VALUES (4, "Lisa");
INSERT INTO SC VALUES(1, "A");
INSERT INTO SC VALUES(3, "B");
INSERT INTO SC VALUES(4, "B");

左连接查询

SELECT name,grand 
FROM student 
LEFT JOIN SC ON student.id=SC.id AND SC.id <2 
WHERE student.id >0;

To be continue....

Leave a comment

Archives

Creative Commons License
This blog is licensed under a Creative Commons License.