我有一个类似于这个简化示例的查询:
select u.id, sq.score
from usr as u,
(select user_id, score FROM score WHERE bar = ?) as sq
where u.id = sq.user_id
我希望join(u.id = sq.user_id)是一个外连接。我无法弄清楚如何在from子句中使用JOIN和' select'像这样。
我知道我可以做这个例子而不必在from子句中使用select,但这不是我在我的应用程序中需要的。
答案 0 :(得分:2)
这样的事情:
select u.id, sq.score
from usr as u
left join ( -- or right/full join as per your needs
select user_id, score FROM score WHERE bar = ?
) as sq
on u.id = sq.user_id