I'm building a application and have this table for users relationships. I need to build some queries like for example:
- Who invited me as a friend?
- Who I invited to be my friend?
- Who I accept as friend?
And need some help because for me are complex queries :(. Also I don't know if open trhead for each of the question or leave all them here in this topic, what's the best?
For the first question: I have this table structure: http://www.dropmocks.com/mBjNvF and need to get the id_user_app if not exists in id_user_rq as the title said. I try this query:
SELECT DISTINCT A.*, p.*, u.email FROM default_relations_users A LEFT JOIN default_relations_users B ON (A.id_user_rq = B.id_user_ap AND A.id_user_ap = B.id_user_rq AND A.id_user_rq = 1) LEFT JOIN default_users u ON (u.id = A.id_user_rq) LEFT JOIN default_profiles p ON (p.user_id = A.id_user_rq) GROUP BY A.id_user_rq
But it's not working, any advice or help?