Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Oracle SQL social network queries?

I am working on small relational database queries for school. I have tried several things but these queries aren't working out for me. I can paste what I tried for every one but suggestions are more than welcome at this point as time is running out.

Table: Users

Attributes: Id_pk, Name, Gender

Table: Friends

Attributes: Id1_pk (fk to users.id), Id2_pk (fk to users.id),Startdate

Table: Comments

Attributes: CommentID_pk, Poster (fk to users.id), Recipient (fk to users.id), Text, PostDate

I am currently working on a query to show all pairs of males and females who are friends since this year. So far I am trying this:

Select *

from users a, users b, friends

where id1 = a.id and a.gender = 'M' and id2 = b.id and b.gender = 'F';

intersect

Select *

from users a, users b, friends

where id2 = a.id and a.gender = 'M' and id1 = b.id and b.gender = 'F';

I am trying to form a query that makes sure they are of opposite gender with matching ID's.

1 Answer

Relevance
  • Merc
    Lv 6
    8 years ago
    Favorite Answer

    Instead of a union you can do "and a.gender <> b.gender", can't you?

Still have questions? Get your answers by asking now.