PSQL外连接保持连接列唯一

时间:2015-02-16 15:37:49

标签: sql postgresql join outer-join psql

假设我有两个表如下所示:

学生

age|name|gender
---+----+------
 3 |jon | M
 4 |mike| M
 2 |Sue | F

师:

experience|name|college
----------+----+-------
10 years  |Sue | UVA
23 years  |Tom | Yale
9 years   |Bob | Harvard

在执行外部联接时,如何在识别Sue Teacher和Sue Student之间的差异的同时组合此表?

1 个答案:

答案 0 :(得分:0)

您的意思是UNION而不是外部联接吗?

SELECT 'student' as type, name
  FROM student
 UNION SELECT 'teacher' as type, name
  FROM teacher