SQL 2加入一个查询

时间:2017-06-14 01:01:41

标签: sql join

我无法理解这个SQL。我有这3张桌子(见下图)。我需要找到一种方法来提取人的姓名和婚姻状况。我知道我需要2个联接,但我无法让它工作。

期望的输出:

John   Married
Mary   Widow

表:

person_per

per_ID   per_FirstName
   1     John
   2     Mary

person_custom

per_ID   status_code
   1         2
   2         4

list_lst

status_code   ???  
     1        Married
     2        Single
     3        Divorced
     4        Widow

1 个答案:

答案 0 :(得分:3)

select per_FirstName, l.[status] /* you didn't put a name for that column */
from person_per p
inner join person_custom c on c.per_ID = p.per_ID
inner join list_lst l on l.status_code = c.status_code