SELECT 来自不同的 table 和 LEFT JOIN

SELECT from different table and LEFT JOIN

原查询是

SELECT user_id, user_location, displayname FROM engine4_users WHERE user_location IS NOT NULL

打印 user_id、user_location 和显示名称,

Ex:
1 30,32 demo
2 30,31 demo
3 33,32 demo

但现在我需要从另一个 table 获取用户图片,我有这个,

SELECT  s.storage_path as url FROM engine4_storage_files as s
LEFT JOIN  engine4_users as u ON s.file_id = u.photo_id

只打印 URL

我需要的是将 url 添加到第一个查询

试试这个:

SELECT u.user_id, u.user_location, u.displayname, s.storage_path as url 
FROM engine4_users u 
LEFT JOIN engine4_storage_files s
ON s.file_id = u.photo_id 
WHERE u.user_location IS NOT NULL

根据评论中的要求扩展:

SELECT u.user_id, u.user_location, u.displayname, w.value as about, s.storage_path as url 
FROM engine4_users u 
LEFT JOIN engine4_user_fields_values w 
ON w.item_id = u.user_id
LEFT JOIN engine4_storage_files s
ON s.file_id = u.photo_id 
WHERE u.user_location IS NOT NULL