🔥🔥🔥3 solutions in MySQL  | Beats 95.47%🔥🔥🔥
1. Brute force solution with sub-query with runtime 1071ms beats 40.57%

Time complexity: O(N * M)


Space complexity: O(N + M + R) => N = total rows from first
# 1. Brute force solution with sub-query with runtime 1071ms beats 40.57%
- Time complexity: O(N * M)

- Space complexity: O(N + M + R) => N = total rows from first sub-query, M= Total rows from second sub-query, R = total rows after UNION

# Code
```mysql []
SELECT 
    employee_id
FROM employees
WHERE employee_id NOT IN (	
		SELECT 
            employee_id
        FROM salaries
) 
UNION 
SELECT 
    employee_id
FROM salaries
WHERE employee_id NOT IN 
		(SELECT 
            employee_id
        FROM employees
)
ORDER BY employee_id;
```


# 2. Solution with Join with runtime 1184ms beats 29.10%
- Time complexity: O(M × N) + O(N × M) + O(K log K) => union & order by costs O(K log K)

- Space complexity: O(M × N)

# Code
```mysql []
SELECT 
    e.employee_id
FROM employees e
LEFT JOIN salaries s ON e.employee_id = s.employee_id
WHERE s.employee_id IS NULL 
UNION 
SELECT 
    s.employee_id
FROM salaries s
LEFT JOIN employees e ON e.employee_id = s.employee_id
WHERE e.employee_id IS NULL
ORDER BY employee_id;
```

# 3. Optimal solution with Correlated sub-query with runtime 556ms beats 95.47%
 - Time complexity: O(M × N)

 - Space complexity: O(K) => K is the number of rows of unmatched employees in both table 

# Code
```mysql []
SELECT 
    e.employee_id
FROM employees e
WHERE NOT EXISTS(
		SELECT 
            1
        FROM salaries s
        WHERE e.employee_id = s.employee_id
) 
UNION 
SELECT 
    s.employee_id
FROM salaries s
WHERE NOT EXISTS(
		SELECT 
            1
        FROM
            employees e
        WHERE
            e.employee_id = s.employee_id
)
ORDER BY employee_id;
```
['Database', 'MySQL']