MySQL Forums
Forum List  »  InnoDB

Re: Sophisticated SELECT statement, help me do the math!
Posted by: egal egal
Date: April 09, 2008 06:39AM

maybe this could help!

your ID is 1

your table
-----------------

member_id | users_login_id
1 | 3
1 | 2
4 | 1
3 | 5
5 | 4
8 | 9
7 | 9

result for user id = 1
----------------------------

member_id | users_login_id
3 | 5
5 | 4



query
----------------------

SELECT *
FROM (
(

SELECT member_id AS friendsID
FROM users_friends
WHERE users_login_id = '1'
)
UNION (

SELECT users_login_id AS friendsID
FROM users_friends
WHERE member_id = '1'
)
ORDER BY friendsID
) AS my_friends
INNER JOIN users_friends AS of_friends ON ( of_friends.member_id = my_friends.friendsID
OR of_friends.users_login_id = my_friends.friendsID )
WHERE of_friends.member_id != '1'
AND of_friends.users_login_id != '1'

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Sophisticated SELECT statement, help me do the math!
1930
April 09, 2008 06:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.