我有两张桌子:
Providers
----------------------------
| ID | NAME |
----------------------------
| 1 | Dr. Brown |
----------------------------
| 2 | Dr. Smith |
----------------------------
| 3 | Nurse Jones |
----------------------------
| 4 | Stan Lee, NP |
----------------------------
Provider_Tax_ID
----------------------------
| ID | TAX_ID |
----------------------------
| 2 | 79465654 |
----------------------------
| 3 | 32613322 |
----------------------------
尝试将Providers
与其税号相匹配时,我想提取所有提供商,包括无法加入Provider_Tax_ID
的提供商。
所以我的结果如下:
--------------------------------------------------
| ID | NAME | TAX_ID |
--------------------------------------------------
| 1 | Dr. Brown | NULL |
--------------------------------------------------
| 2 | Dr. Smith | 79465654 |
--------------------------------------------------
| 3 | Nurse Jones | 32613322 |
--------------------------------------------------
| 4 | Stan Lee, NP | NULL |
--------------------------------------------------
我尝试过这样的事情,但我没有得到任何结果:
SELECT
p.ID,
p.NAME,
t.TAX_ID
FROM
providers p
FULL OUTER JOIN provider_tax_id t on p.ID = t.ID
答案 0 :(得分:2)
您只需要一个左(外)联接:
SELECT
p.ID,
p.NAME,
t.TAX_ID
FROM
providers p
LEFT OUTER JOIN provider_tax_id t on p.ID = t.ID