I have this table:
SUBSCRIPTION
NAME SUBSCRIBER
It’s essentially a table having a list of people who subscribe to each other. I want to write a query that outputs a list of tuples such that, if the set B represents all those people who subscribe to A, B also represents those people that A doesn’t subscribe to. ie, find a list of people who are not mutually subscribed to each other.
This is the query that I wrote:
SELECT A.name, B.name
FROM subscription AS A, subscription AS B
WHERE A.subscriber=B.name AND A.name!=B.subscriber;
ie, it should display two columns A and B where B subscribes to A and A doesn’t subscribe to B.
All I’m getting is garbage with a lot of rows duplicated. What am I doing wrong in this?
Well, I made a mistake while stating the samples. The samples go like this:
Melissa, Joan subscribe to John.
Charles, John subscribe to Joan.
Charles subscribes to Melissa.
melissa, joan subscribe to Charles.
the first part refers to the subscriber column and the second to the name column.
ie, John’s the name and melissa, joan subscribe to john.
therfore, it should output (melissa,john) because john doesn’t subscribe to melissa.
How would this change the query?
This pulls all records from the subscription table where there isn’t a corresponding match in the subscription table for the opposite subscription.