我正在尝试在下面运行脚本,但总是为 name 字段获取 NULL 值。
SELECT u.name AS _user_name, s.name AS _school_name
FROM fwg_files AS f
LEFT JOIN users AS u ON u.id = f.user_id
LEFT JOIN user_profiles AS up ON up.user_id = u.id
LEFT JOIN school AS s ON s.id = up.profile_value
在我看来,这个问题在 JOIN ON school 表中,我尝试 SELECT s.id 并且它也返回 NULL 值。当我将最后一行更改为 RIGHT JOIN 时,它开始工作,但我只能看到 s.name 值,其他为 NULL
表 fwg_files
id | user_id
240 | 414
241 | 436
表用户
id | name
414 | Name 1
436 | Name 2
表 user_profiles
user_id | profile_value
414 | "6"
436 | "14"
表学校
id | name
6 | School 1
14 | School 2
谢谢