I'm writing a SQL script to check the integrity of a MySQL DB. The queries check different aspects of different tables, so they're not related. I don't want to relate them. I just want to see the results of the different queries one after the other.
The individual queries work fine, but I'd like to run them at the same time, but keep the results separate. They can return nothing or they can return multiple rows. (Ideally, I'd like headings to make the results more legible.)
The error is
"Error code: 1242. Subquery returns more than 1 row"
Here's what I've tried:
SELECT
(-- Teams not associated with any employees
SELECT id
FROM teams
WHERE NOT EXISTS
(SELECT id
FROM employee_teams
WHERE employee_teams.teamID IN(teams.id))) AS TeamNoEmployee,
(-- Teams deleted but associated with employees
SELECT teamID
FROM employee_teams
WHERE NOT EXISTS
(SELECT id
FROM teams
WHERE teams.id IN(employee_teams.teamID))) AS TeamsDeleted
Update: @JohnHC got it. Here's my new version. I need to be able to add a header for each query so I can tell them apart.
-- Teams not associated with any employees
SELECT 'Team No Employee' AS Test, id
FROM teams
WHERE NOT EXISTS
(SELECT id
FROM employee_teams
WHERE employee_teams.teamID IN(teams.id))
UNION
-- Teams deleted but associated with employees
SELECT 'Teams Deleted', teamID
FROM employee_teams
WHERE NOT EXISTS
(SELECT id
FROM teams
WHERE teams.id IN(employee_teams.teamID))