How to exclude rows when using a LEFT JOIN (MySQL)
问题 I have users with many posts . I want to build an SQL query that would do the following in 1 query (no subquery), and hopefully no unions if possible. I know I can do this with union but I want to learn if this can be done using only joins. I want to get a list of distinct active users who: have no posts have no approved posts Here's what I have so far: SELECT DISTINCT u.* FROM users u LEFT JOIN posts p ON p.user_id = u.id LEFT JOIN posts p2 ON p2.user_id = u.id WHERE u.status = 'active' AND