需要一个子查询:
table Post:
id
name
...
table Favorite:
id
user_id
post_id
...
SELECT post_id, user_id FROM
(SELECT
post.id AS post_id, favorite.user_id AS user_id
FROM post LEFT OUTER JOIN favorite on
post.id = favorite.post_id) AS post_with_favorite
WHERE user_id = ... OR user_id IS NULL;