select * from posts p
left join post_user us
on us.post_id = p.id
left join users u
on us.user_id = u.id
where us.checked="checked"
where us.cheked-out="checked"
select * from ( select us.post_id,count(1) c from posts p
left join post_user us
on p.id = us.post_id
group by us.checked,p.post_id ) t
left join post_user us
on us.post_id = t.post_id
left join users u
on us.user_id = u.id
where t.c=1
commented on September 19th 19 at 00:38SELECT DISTINCT
pu2.post_id
FROM (SELECT
t.post_id,
COUNT(1)
FROM (SELECT
pu.post_id,
cheked-out
FROM post_user pu
GROUP BY pu.post_id,
pu.cheked-out) t
GROUP BY t.post_id
HAVING COUNT(1) = 1) t2
LEFT JOIN post_user pu2
ON pu2.post_id = t2.post_id
WHERE pu2.cheked-out = "checked"
commented on September 19th 19 at 00:44SELECT
pu.post_id,
cheked-out
FROM post_user pu
GROUP BY pu.post_id,
pu.cheked-out
Find more questions by tags MySQL
better
- Mittie22 commented on September 19th 19 at 00:39
SELECT * FROM posts p WHERE p.id IN(
(SELECT DISTINCT
pu2.post_id
FROM (SELECT
t.post_id,
COUNT(1)
FROM (SELECT
pu.post_id,
cheked-out
FROM post_user pu
GROUP BY pu.post_id,
pu.cheked-out) t
GROUP BY t.post_id
HAVING COUNT(1) = 1) t2
LEFT JOIN post_user pu2
ON pu2.post_id = t2.post_id
WHERE pu2.cheked-out = "checked"))
https://drive.google.com/file/d/0B8tEf6QRhrDMc09Dc... - giuseppe.Beah commented on September 19th 19 at 00:48