How can I optimize this query? It seems there should be a much easier way to do this. The goal is that it will still be able to be readily turned into a delete statement.
SELECT * FROM team
WHERE team_id IN (
SELECT team_id
FROM (
SELECT team.team_id, (
SELECT COUNT(*)
FROM signup
WHERE signup.team_id = team.team_id
) AS members
FROM team, schedule, event
WHERE team.schedule_id = schedule.schedule_id
AND schedule.event_id = event.event_id
AND event.event_id =183) AS t
WHERE members = 0
)
A quick glance at this query gives me this:
It looked like you’re trying to find all teams that are in an event but are not in the signup table. Is this accurate?
Also, I wanted to note that it will be faster to do joins then a bunch of subqueries, especially if the subqueries depend on each row (in your case, they do).
Cheers,
Eric