I have two tables:
users
id | admin_id | name
-----------------------
1 | 10 | a
2 | 10 | b
3 | 15 | c
4 | 10 | d
5 | 10 | e
6 | 10 | f
status
id | user_id | status
-----------------------
1 | 2 | error
2 | 2 | success
3 | 2 | error
4 | 4 | success
5 | 6 | error
now I am trying to get all users of admin_id 10 who don't have any entry in table status and the users which don't have any entry with status success in status table by using group by clause. My expected results are:
Result:
id | admin_id | name | status
------------------------------------
1 | 10 | a | null
5 | 10 | e | null
6 | 10 | f | error
So as per the expected results the query should ignore the user_id 2,4 because these two have success status in status table. Right now I am trying to make the query like this:
SELECT
users.*,
status.status
FROM
users
LEFT JOIN
status ON users.id = status.user_id
WHERE
users.admin_id = 10 AND status.status != "success"
GROUP BY
users.id
It can be done by sub-query but my requirement is to do it with single query and without using sub-query.
Is there a way to do this?
Thanks!