我有以下数据库表:
People
+--------+------------+------------+-----------+
| f_ID | F_NAME | STUFF | F_VALUE |
+--------+------------+------------+-----------+
| 1 | Zoe | blah | 101 |
| 2 | Jimy | derka | 202 |
| 3 | Kate | shazam | 20 |
| 4 | Sue | pow | 2 |
+--------+------------+------------+-----------+
RESULTS
+------- ---+------------+
| F_ID | RESULTS |
+-----------+------------+
| 1 | Good |
| 4 | OK |
+-----------+------------+
如何创建查询以显示人员表中的所有条目,如下所示:
+------------+------------+
| NAME | GRADE |
+------------+------------+
| Zoe | Good |
| Jimy | N/A |
| Kate | N/A |
| Sue | OK |
+------------+------------+
我试过这个查询,但它不能正常工作:
SELECT
NAME
GRADE
(
SELECT
p.F_NAME AS NAME,
r.RESULTS
FROM People p
JOIN RESULTS r ON r.F_ID=p.F_ID
UNION
SELECT
p.F_NAME AS NAME,
"N/A"
FROM People p
JOIN RESULTS r ON r.F_ID=p.F_ID
)a