SQL query for fetching friend list

Posted by Bhavyanshu on Stack Overflow See other posts from Stack Overflow or by Bhavyanshu
Published on 2012-10-23T22:57:25Z Indexed on 2012/10/23 23:00 UTC
Read the original article Hit count: 121

Filed under:
|

I need help with SQL query.

I have two tables. One is users and other one is userfriends

users table:
aid email                    firstname 
1   [email protected]         example
2   [email protected]        example2
3   [email protected]        example3
4   [email protected]        example4

userfriends tables:
reqid     email                    friendemail               status 
1         [email protected]        [email protected]            1       (example1 is frnds with example2)
2         [email protected]        [email protected]            2       (example2 request pending)
3         [email protected]        [email protected]            1       (example1 is frnds with example3)
4         [email protected]        [email protected]            1       (example1 is frnds with example4)

So when status is 2 the add request is pending and at status 1 they are friends. What i want is that i want to retrieve the complete friendlist for user example1. I want to pull out names from users table for corresponding output from previous query to display as friendlist.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql