-1
SELECT DISTINCT(e.ssn), c.class     
FROM enrollment e
CROSS JOIN 
class c
WHERE NOT EXISTS
(
    SELECT *
    FROM enrollment e2
);

So, I'm trying to first get a table with the ssn and class attributes in it and then I want to only keep the rows that are not in the enrollment table, I tried this but it doesn't seem to work.

Shadow
  • 33,525
  • 10
  • 51
  • 64
d96
  • 1
  • 1
    Please add a few rows of sample data and the expected result. Seems like an anti-join will produce the result you want but it's difficult to tell from the explanation. – The Impaler Mar 20 '22 at 19:26
  • 1
    It'd be easier to help if you posted sample data from both tables, the actual results and what you expected them to be instead (all as text, not screen shots) – SOS Mar 20 '22 at 19:27

1 Answers1

0

To get the lines from table1 where there is no matching value in table2 we can write:

Select table1.*
From table1
Left join table2
On table1.joiningColumn
  = Tables.joiningColumn
Where table2.joiningColumn is null;

The left join means that we get all rows from table1 whether they match or not and the where clause rejects the rows which are matched.