I have two tables Invitations and Users, both table contain some emails.
I want to count those emails which are present in the Invitation table but not present in the Users table
Invitation
InvitationID Email
-------------------------------------
1 test@test.com
2 someone@example.com
3 test12@test.com
Users
UserName IsActive
-------------------------------------
test@test.com InActive
sample12@sample.com Active
test12@test.com InActive
I tried it like this
SELECT COUNT(*) FROM Invitations, Users
where Invitations.Email <> Users.UserName
I want like this
Count=1
You’re getting the wrong answer because you’re counting the wrong thing.
Imagine two records, a and b in each table. a<>b and b<>a so you’ll get 2, not the 0 you’re expecting.
Try this instead