Problem
I have two different tables, table names are team_request and teams. [team_request] have unique records of each team submitted and [teams] saves duplicate records with unique username's but same team data as in [team_request] for the user who accepted to be part of that team.
Expected result from below query:
I am running the below query to fetch the pending challenges or team request, which have a basic logic of fetch all the teams from [team_request] where that team doesn't exists in [teams] table or hasn't been ignored by that user.
Actually what query is doing:
It's fetching all the rows (teams) from table [team_request] which belongs to that user, no matter whether a user has excepted or ignored.
Also forgot to mention above fbC_status is a field in [team_request] which saves user's email address if that user has ignored to be part of the team.
Any help or guidance will be appreciated I just got stuck with it.
MySQL Query
SELECT *
FROM team_request
WHERE (c_emails LIKE '%joe@example.com%')
OR (c_emails LIKE '%9876543210%')
AND fbC_status NOT LIKE '%joe@example.com%'
AND fbC_status NOT LIKE '%9876543210%'
AND '%joe@example.com%' NOT IN
(SELECT username
FROM teams)
AND t_name NOT IN
(SELECT T.t_name
FROM team_request TR,
teams T
WHERE TR.t_name = T.t_name
AND T.username = '%joe@example.com%'
AND (TR.fbC_status NOT LIKE '%joe@example.com%'
AND TR.fbC_status NOT LIKE '%9876543210%'))
LIMIT 0, 30