Reputation: 65
i have two tables
--table a--
first second
------ -------
user-1 user-2
user-2 user-1
user-2 user-3
--table b--
ignoreby ignored
-------- -------
user-1 user-2
user-1 user-4
user-3 user-4
i want to select the records from table a which are not ignoring themself(including unidirectional records) on table b
The result here would be: user-2 user-3
The record user-2 user-1 should not be included in the result because user-1 ignores user-2 and this is unidirectional.
Thanks
Upvotes: 2
Views: 60
Reputation: 554
Maybe you can try a different and more simpler approach. Like adding a column called is_ignored with a boolean value to your first table (Table a). Then you can directly see with a single select if the user ignored the other user.
Upvotes: 1
Reputation: 1270391
Do you mean "bidirectional" and not "unidirectional"? If so:
select a.*
from tablea a
where not exists (select 1
from tableb b
where (b.ignoreby = a.first and b.ignored = a.second) or
(b.ignoreby = a.second and b.ignored = a.first)
);
If you really do mean "unidirectional", then you would only use the first condition.
Upvotes: 2