Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this table structure: and need to get the id_user_rq if not exists in id_user_ap as the title said. I need to get the rows where id_user_rq = 1 and id_user_ap = 2 and id_user_rq = 2 and id_user_ap = 1 meaning that I send a invitation and the other part accept me and inverse the relation, any help?

share|improve this question
up vote 2 down vote accepted

Please try this:

(SELECT * FROM default_relation_users WHERE id_user_rq = 1) A
(SELECT * FROM default_relation_users WHERE id_user_ap = 1) B
(A.id_user_rq=B.id_user_ap AND B.id_user_rq=A.id_user_ap)
WHERE B.id_user_ap IS NOT NULL;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.