有两张表a和b。a中有字段学号(id),姓名(name)。b中有字段学号(id),成绩(score)。
我想将这两张表联合起来。用select a.id a.name b.score from a,b where a.id=b.id
但是假如我此时a中有数据如下
id name
1 a
2 b
而b中的数据如下:
id score
1 100
表中并没有学号为2的信息。如果我通过上面的语句讲这两张表联立起来,表中将没有2的信息。如果我想让新表中有2的信息,将score置空就行,应该怎么写呢?
麻烦了~谢谢!
我想将这两张表联合起来。用select a.id a.name b.score from a,b where a.id=b.id
但是假如我此时a中有数据如下
id name
1 a
2 b
而b中的数据如下:
id score
1 100
表中并没有学号为2的信息。如果我通过上面的语句讲这两张表联立起来,表中将没有2的信息。如果我想让新表中有2的信息,将score置空就行,应该怎么写呢?
麻烦了~谢谢!
from a left join
b on
a.id=b.id;
from a left join
b on
a.id=b.id;
... LEFT OUTER JOIN ... ON ...
对如本题问即为:
SELECT a.id,name,score
FROM a LEFT OUTER JOIN b ON a.id=b.id
select id,name,score from a left outer join b using(id)